
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Spring框架 · 书名</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="作者">
        <meta name="identifier" content="图书编号" scheme="ISBN">
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-intopic-toc/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-flexible-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    
    <link rel="prev" href="springmvc框架.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    书名
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Books</li>
        
        
    
        <li class="chapter " data-level="2.1" >
            
                <span>
            
                    
                    Java
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="../java/001环境变量.html">
            
                <a href="../java/001环境变量.html">
            
                    
                    001环境变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="../java/002Java初体验.html">
            
                <a href="../java/002Java初体验.html">
            
                    
                    002Java初体验
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="../java/003变量命名及数据类型.html">
            
                <a href="../java/003变量命名及数据类型.html">
            
                    
                    003变量命名及数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="../java/004运算符.html">
            
                <a href="../java/004运算符.html">
            
                    
                    004运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.5" data-path="../java/005选择结构.html">
            
                <a href="../java/005选择结构.html">
            
                    
                    005选择结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.6" data-path="../java/006循环结构.html">
            
                <a href="../java/006循环结构.html">
            
                    
                    006循环结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.7" data-path="../java/007数组.html">
            
                <a href="../java/007数组.html">
            
                    
                    007数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.8" data-path="../java/008类和对象方法.html">
            
                <a href="../java/008类和对象方法.html">
            
                    
                    008类和对象方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.9" data-path="../java/009构造方法.html">
            
                <a href="../java/009构造方法.html">
            
                    
                    009构造方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.10" data-path="../java/010封装与关键字static.html">
            
                <a href="../java/010封装与关键字static.html">
            
                    
                    010封装与关键字Static
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.11" data-path="../java/011 继承.html">
            
                <a href="../java/011 继承.html">
            
                    
                    011 继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.12" data-path="../java/012方法重写.html">
            
                <a href="../java/012方法重写.html">
            
                    
                    012方法重写
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.13" data-path="../java/013多态.html">
            
                <a href="../java/013多态.html">
            
                    
                    013多态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.14" data-path="../java/014抽象类抽象方法.html">
            
                <a href="../java/014抽象类抽象方法.html">
            
                    
                    014抽象类抽象方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.15" data-path="../java/015接口.html">
            
                <a href="../java/015接口.html">
            
                    
                    015接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.16" data-path="../java/016异常.html">
            
                <a href="../java/016异常.html">
            
                    
                    016异常
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.17" data-path="../java/017集合.html">
            
                <a href="../java/017集合.html">
            
                    
                    017集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.18" data-path="../java/017集合2.html">
            
                <a href="../java/017集合2.html">
            
                    
                    017集合2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.19" data-path="../java/018泛型.html">
            
                <a href="../java/018泛型.html">
            
                    
                    018泛型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.20" data-path="../java/019Collections算法类.html">
            
                <a href="../java/019Collections算法类.html">
            
                    
                    019Collections算法类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.21" data-path="../java/020枚举.html">
            
                <a href="../java/020枚举.html">
            
                    
                    020枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.22" data-path="../java/021包装类.html">
            
                <a href="../java/021包装类.html">
            
                    
                    021包装类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.23" data-path="../java/022常用类.html">
            
                <a href="../java/022常用类.html">
            
                    
                    022常用类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.24" data-path="../java/023File类.html">
            
                <a href="../java/023File类.html">
            
                    
                    023File类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.25" data-path="../java/024IO流.html">
            
                <a href="../java/024IO流.html">
            
                    
                    024IO流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.26" data-path="../java/025多线程.html">
            
                <a href="../java/025多线程.html">
            
                    
                    025多线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.27" data-path="../java/025多线程线程池.html">
            
                <a href="../java/025多线程线程池.html">
            
                    
                    025多线程线程池
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.28" data-path="../java/026网络编程Socket.html">
            
                <a href="../java/026网络编程Socket.html">
            
                    
                    026网络编程Socket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.29" data-path="../java/027XML解析.html">
            
                <a href="../java/027XML解析.html">
            
                    
                    027XML解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.30" data-path="../java/028 注解.html">
            
                <a href="../java/028 注解.html">
            
                    
                    028 注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.31" data-path="../java/029 Lambda表达式.html">
            
                <a href="../java/029 Lambda表达式.html">
            
                    
                    029 Lambda表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.32" data-path="../java/029 反射.html">
            
                <a href="../java/029 反射.html">
            
                    
                    029 反射
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.2" >
            
                <span>
            
                    
                    Mybatis
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="../mybatis/MyBatis.html">
            
                <a href="../mybatis/MyBatis.html">
            
                    
                    MyBatis
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1.1" >
            
                <span>
            
                    
                    MyBatis
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" >
            
                <span>
            
                    
                    Mysql
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="../mysql/01 SQL通用语法.html">
            
                <a href="../mysql/01 SQL通用语法.html">
            
                    
                    01 SQL通用语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.2" data-path="../mysql/02 DDL.html">
            
                <a href="../mysql/02 DDL.html">
            
                    
                    02 DDL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.3" data-path="../mysql/03 DML.html">
            
                <a href="../mysql/03 DML.html">
            
                    
                    03 DML
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.4" data-path="../mysql/04 DQL.html">
            
                <a href="../mysql/04 DQL.html">
            
                    
                    04 DQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.5" data-path="../mysql/05 DCL.html">
            
                <a href="../mysql/05 DCL.html">
            
                    
                    05 DCL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.6" data-path="../mysql/06 函数.html">
            
                <a href="../mysql/06 函数.html">
            
                    
                    06 函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.7" data-path="../mysql/07 约束.html">
            
                <a href="../mysql/07 约束.html">
            
                    
                    07 约束
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.8" data-path="../mysql/08 多表查询.html">
            
                <a href="../mysql/08 多表查询.html">
            
                    
                    08 多表查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.9" data-path="../mysql/09 事务.html">
            
                <a href="../mysql/09 事务.html">
            
                    
                    09 事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.10" data-path="../mysql/999zzz.html">
            
                <a href="../mysql/999zzz.html">
            
                    
                    999zzz
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.11" data-path="../mysql/MySql.html">
            
                <a href="../mysql/MySql.html">
            
                    
                    MySql
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.12" data-path="../mysql/sql.html">
            
                <a href="../mysql/sql.html">
            
                    
                    Sql
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" >
            
                <span>
            
                    
                    Spring
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../spring/spring.html">
            
                <a href="../spring/spring.html">
            
                    
                    Spring
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" >
            
                <span>
            
                    
                    SpringMVC
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.5.1" data-path="../springMVC/springMVC.html">
            
                <a href="../springMVC/springMVC.html">
            
                    
                    SpringMVC
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.6" >
            
                <span>
            
                    
                    整合
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.6.1" data-path="Mybatis框架.html">
            
                <a href="Mybatis框架.html">
            
                    
                    Mybatis框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.2" data-path="SpringBoot.html">
            
                <a href="SpringBoot.html">
            
                    
                    SpringBoot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.3" data-path="springmvc框架.html">
            
                <a href="springmvc框架.html">
            
                    
                    Springmvc框架
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.6.4" data-path="spring框架.html">
            
                <a href="spring框架.html">
            
                    
                    Spring框架
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >Spring框架</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="spring&#x6846;&#x67B6;">spring&#x6846;&#x67B6;</h1>
<p><img src="spring&#x6846;&#x67B6;.assets/image-20220625140606335.png" alt="image-20220625140606335"></p>
<h2 id="spring&#x662F;&#x4EC0;&#x4E48;">Spring&#x662F;&#x4EC0;&#x4E48;</h2>
<p>spring &#x662F;&#x76EE;&#x524D;&#x4E3B;&#x6D41;&#x7684; Java Web &#x5F00;&#x53D1;&#x6846;&#x67B6;&#xFF0C;&#x662F; Java &#x4E16;&#x754C;&#x6700;&#x4E3A;&#x6210;&#x529F;&#x7684;&#x6846;&#x67B6;&#x3002;&#x8BE5;&#x6846;&#x67B6;&#x662F;&#x4E00;&#x4E2A;&#x8F7B;&#x91CF;&#x7EA7;&#x7684;&#x5F00;&#x6E90;&#x6846;&#x67B6;&#xFF0C;&#x5177;&#x6709;&#x5F88;&#x9AD8;&#x7684;&#x51DD;&#x805A;&#x529B;&#x548C;&#x5438;&#x5F15;&#x529B;&#x3002;</p>
<p>Spring &#x7531; Rod Johnson &#x521B;&#x7ACB;&#xFF0C;2004 &#x5E74;&#x53D1;&#x5E03;&#x4E86; Spring &#x6846;&#x67B6;&#x7684;&#x7B2C;&#x4E00;&#x7248;&#xFF0C;&#x5176;&#x76EE;&#x7684;&#x662F;&#x7528;&#x4E8E;&#x7B80;&#x5316;&#x4F01;&#x4E1A;&#x7EA7;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x5F00;&#x53D1;&#x7684;&#x96BE;&#x5EA6;&#x548C;&#x5468;&#x671F;&#x3002;</p>
<p>Spring &#x662F;&#x5206;&#x5C42;&#x7684; Java SE/EE &#x4E00;&#x7AD9;&#x5F0F;&#x8F7B;&#x91CF;&#x7EA7;&#x5F00;&#x6E90;&#x6846;&#x67B6;&#xFF0C;&#x4EE5; IoC&#xFF08;Inverse of Control&#xFF0C;&#x63A7;&#x5236;&#x53CD;&#x8F6C;&#xFF09;&#x548C; AOP&#xFF08;Aspect Oriented Programming&#xFF0C;&#x9762;&#x5411;&#x5207;&#x9762;&#x7F16;&#x7A0B;&#xFF09;&#x4E3A;&#x5185;&#x6838;&#x3002;</p>
<p>IoC &#x6307;&#x7684;&#x662F;&#x5C06;&#x5BF9;&#x8C61;&#x7684;&#x521B;&#x5EFA;&#x6743;&#x4EA4;&#x7ED9; Spring &#x53BB;&#x521B;&#x5EFA;&#x3002;&#x4F7F;&#x7528; Spring &#x4E4B;&#x524D;&#xFF0C;&#x5BF9;&#x8C61;&#x7684;&#x521B;&#x5EFA;&#x90FD;&#x662F;&#x7531;&#x6211;&#x4EEC;&#x4F7F;&#x7528; new &#x521B;&#x5EFA;&#xFF0C;&#x800C;&#x4F7F;&#x7528; Spring &#x4E4B;&#x540E;&#xFF0C;&#x5BF9;&#x8C61;&#x7684;&#x521B;&#x5EFA;&#x90FD;&#x4EA4;&#x7ED9;&#x4E86; Spring &#x6846;&#x67B6;&#x3002;AOP &#x7528;&#x6765;&#x5C01;&#x88C5;&#x591A;&#x4E2A;&#x7C7B;&#x7684;&#x516C;&#x5171;&#x884C;&#x4E3A;&#xFF0C;&#x5C06;&#x90A3;&#x4E9B;&#x4E0E;&#x4E1A;&#x52A1;&#x65E0;&#x5173;&#xFF0C;&#x5374;&#x4E3A;&#x4E1A;&#x52A1;&#x6A21;&#x5757;&#x6240;&#x5171;&#x540C;&#x8C03;&#x7528;&#x7684;&#x903B;&#x8F91;&#x5C01;&#x88C5;&#x8D77;&#x6765;&#xFF0C;&#x51CF;&#x5C11;&#x7CFB;&#x7EDF;&#x7684;&#x91CD;&#x590D;&#x4EE3;&#x7801;&#xFF0C;&#x964D;&#x4F4E;&#x6A21;&#x5757;&#x95F4;&#x7684;&#x8026;&#x5408;&#x5EA6;&#x3002;&#x53E6;&#x5916;&#xFF0C;AOP &#x8FD8;&#x89E3;&#x51B3;&#x4E00;&#x4E9B;&#x7CFB;&#x7EDF;&#x5C42;&#x9762;&#x4E0A;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x6BD4;&#x5982;&#x65E5;&#x5FD7;&#x3001;&#x4E8B;&#x52A1;&#x3001;&#x6743;&#x9650;&#x7B49;</p>
<h2 id="spring-&#x6846;&#x67B6;&#x7279;&#x70B9;">Spring &#x6846;&#x67B6;&#x7279;&#x70B9;</h2>
<p><strong>1&#xFF09;&#x65B9;&#x4FBF;&#x89E3;&#x8026;&#xFF0C;&#x7B80;&#x5316;&#x5F00;&#x53D1;</strong></p>
<p>Spring &#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x5927;&#x5DE5;&#x5382;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x6240;&#x6709;&#x5BF9;&#x8C61;&#x7684;&#x521B;&#x5EFA;&#x548C;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#x7684;&#x7EF4;&#x62A4;&#x4EA4;&#x7ED9; Spring &#x7BA1;&#x7406;&#x3002;</p>
<p><strong>2&#xFF09;&#x65B9;&#x4FBF;&#x96C6;&#x6210;&#x5404;&#x79CD;&#x4F18;&#x79C0;&#x6846;&#x67B6;</strong></p>
<p>Spring &#x4E0D;&#x6392;&#x65A5;&#x5404;&#x79CD;&#x4F18;&#x79C0;&#x7684;&#x5F00;&#x6E90;&#x6846;&#x67B6;&#xFF0C;&#x5176;&#x5185;&#x90E8;&#x63D0;&#x4F9B;&#x4E86;&#x5BF9;&#x5404;&#x79CD;&#x4F18;&#x79C0;&#x6846;&#x67B6;&#xFF08;&#x5982; Struts2&#x3001;Hibernate&#x3001;MyBatis &#x7B49;&#xFF09;&#x7684;&#x76F4;&#x63A5;&#x652F;&#x6301;&#x3002;</p>
<p><strong>3&#xFF09;&#x964D;&#x4F4E; Java EE API &#x7684;&#x4F7F;&#x7528;&#x96BE;&#x5EA6;</strong></p>
<p>Spring &#x5BF9; Java EE &#x5F00;&#x53D1;&#x4E2D;&#x975E;&#x5E38;&#x96BE;&#x7528;&#x7684;&#x4E00;&#x4E9B; API&#xFF08;JDBC&#x3001;JavaMail&#x3001;&#x8FDC;&#x7A0B;&#x8C03;&#x7528;&#x7B49;&#xFF09;&#x90FD;&#x63D0;&#x4F9B;&#x4E86;&#x5C01;&#x88C5;&#xFF0C;&#x4F7F;&#x8FD9;&#x4E9B; API &#x5E94;&#x7528;&#x7684;&#x96BE;&#x5EA6;&#x5927;&#x5927;&#x964D;&#x4F4E;&#x3002;</p>
<p><strong>4&#xFF09;&#x65B9;&#x4FBF;&#x7A0B;&#x5E8F;&#x7684;&#x6D4B;&#x8BD5;</strong></p>
<p>Spring &#x652F;&#x6301; JUnit4&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x6CE8;&#x89E3;&#x65B9;&#x4FBF;&#x5730;&#x6D4B;&#x8BD5; Spring &#x7A0B;&#x5E8F;&#x3002;</p>
<p><strong>5&#xFF09;AOP &#x7F16;&#x7A0B;&#x7684;&#x652F;&#x6301;</strong></p>
<p>Spring &#x63D0;&#x4F9B;&#x9762;&#x5411;&#x5207;&#x9762;&#x7F16;&#x7A0B;&#xFF0C;&#x53EF;&#x4EE5;&#x65B9;&#x4FBF;&#x5730;&#x5B9E;&#x73B0;&#x5BF9;&#x7A0B;&#x5E8F;&#x8FDB;&#x884C;&#x6743;&#x9650;&#x62E6;&#x622A;&#x548C;&#x8FD0;&#x884C;&#x76D1;&#x63A7;&#x7B49;&#x529F;&#x80FD;&#x3002;</p>
<p><strong>6&#xFF09;&#x58F0;&#x660E;&#x5F0F;&#x4E8B;&#x52A1;&#x7684;&#x652F;&#x6301;</strong></p>
<p>&#x53EA;&#x9700;&#x8981;&#x901A;&#x8FC7;&#x914D;&#x7F6E;&#x5C31;&#x53EF;&#x4EE5;&#x5B8C;&#x6210;&#x5BF9;&#x4E8B;&#x52A1;&#x7684;&#x7BA1;&#x7406;&#xFF0C;&#x800C;&#x65E0;&#x987B;&#x624B;&#x52A8;&#x7F16;&#x7A0B;</p>
<h2 id="spring&#x4F53;&#x7CFB;&#x7ED3;&#x6784;">Spring&#x4F53;&#x7CFB;&#x7ED3;&#x6784;</h2>
<p>Spring &#x6846;&#x67B6;&#x91C7;&#x7528;&#x5206;&#x5C42;&#x7684;&#x7406;&#x5FF5;&#xFF0C;&#x6839;&#x636E;&#x529F;&#x80FD;&#x7684;&#x4E0D;&#x540C;&#x5212;&#x5206;&#x6210;&#x4E86;&#x591A;&#x4E2A;&#x6A21;&#x5757;&#xFF0C;&#x8FD9;&#x4E9B;&#x6A21;&#x5757;&#x5927;&#x4F53;&#x53EF;&#x5206;&#x4E3A; Data Access/Integration&#xFF08;&#x6570;&#x636E;&#x8BBF;&#x95EE;&#x4E0E;&#x96C6;&#x6210;&#xFF09;&#x3001;Web&#x3001;AOP&#x3001;Aspects&#x3001;Instrumentation&#xFF08;&#x68C0;&#x6D4B;&#xFF09;&#x3001;Messaging&#xFF08;&#x6D88;&#x606F;&#x5904;&#x7406;&#xFF09;&#x3001;Core Container&#xFF08;&#x6838;&#x5FC3;&#x5BB9;&#x5668;&#xFF09;&#x548C; Test&#x3002;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#xFF08;&#x4EE5;&#x4E0B;&#x662F; Spring Framework 4.x &#x7248;&#x672C;&#x540E;&#x7684;&#x7CFB;&#x7EDF;&#x67B6;&#x6784;&#x56FE;&#xFF09;</p>
<p><img src="spring&#x6846;&#x67B6;.assets/1031053202.png" alt="1031053202"></p>
<p>&#x4E0A;&#x56FE;&#x4E2D;&#x5305;&#x542B;&#x4E86; Spring &#x6846;&#x67B6;&#x7684;&#x6240;&#x6709;&#x6A21;&#x5757;&#xFF0C;&#x8FD9;&#x4E9B;&#x6A21;&#x5757;&#x53EF;&#x4EE5;&#x6EE1;&#x8DB3;&#x4E00;&#x5207;&#x4F01;&#x4E1A;&#x7EA7;&#x5E94;&#x7528;&#x5F00;&#x53D1;&#x7684;&#x9700;&#x6C42;&#xFF0C;&#x5728;&#x5F00;&#x53D1;&#x8FC7;&#x7A0B;&#x4E2D;&#x53EF;&#x4EE5;&#x6839;&#x636E;&#x9700;&#x6C42;&#x6709;&#x9009;&#x62E9;&#x6027;&#x5730;&#x4F7F;&#x7528;&#x6240;&#x9700;&#x8981;&#x7684;&#x6A21;&#x5757;</p>
<h3 id="1-data-accessintegration&#xFF08;&#x6570;&#x636E;&#x8BBF;&#x95EE;&#xFF0F;&#x96C6;&#x6210;&#xFF09;">1. Data Access/Integration&#xFF08;&#x6570;&#x636E;&#x8BBF;&#x95EE;&#xFF0F;&#x96C6;&#x6210;&#xFF09;</h3>
<p>&#x6570;&#x636E;&#x8BBF;&#x95EE;&#xFF0F;&#x96C6;&#x6210;&#x5C42;&#x5305;&#x62EC; JDBC&#x3001;ORM&#x3001;OXM&#x3001;JMS &#x548C; Transactions &#x6A21;&#x5757;&#xFF0C;&#x5177;&#x4F53;&#x4ECB;&#x7ECD;&#x5982;&#x4E0B;&#x3002;</p>
<ul>
<li>JDBC &#x6A21;&#x5757;&#xFF1A;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A; JBDC &#x7684;&#x6837;&#x4F8B;&#x6A21;&#x677F;&#xFF0C;&#x4F7F;&#x7528;&#x8FD9;&#x4E9B;&#x6A21;&#x677F;&#x80FD;&#x6D88;&#x9664;&#x4F20;&#x7EDF;&#x5197;&#x957F;&#x7684; JDBC &#x7F16;&#x7801;&#x8FD8;&#x6709;&#x5FC5;&#x987B;&#x7684;&#x4E8B;&#x52A1;&#x63A7;&#x5236;&#xFF0C;&#x800C;&#x4E14;&#x80FD;&#x4EAB;&#x53D7;&#x5230; Spring &#x7BA1;&#x7406;&#x4E8B;&#x52A1;&#x7684;&#x597D;&#x5904;&#x3002;</li>
<li>ORM &#x6A21;&#x5757;&#xFF1A;&#x63D0;&#x4F9B;&#x4E0E;&#x6D41;&#x884C;&#x7684;&#x201C;&#x5BF9;&#x8C61;-&#x5173;&#x7CFB;&#x201D;&#x6620;&#x5C04;&#x6846;&#x67B6;&#x65E0;&#x7F1D;&#x96C6;&#x6210;&#x7684; API&#xFF0C;&#x5305;&#x62EC; JPA&#x3001;JDO&#x3001;Hibernate &#x548C; MyBatis &#x7B49;&#x3002;&#x800C;&#x4E14;&#x8FD8;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; Spring &#x4E8B;&#x52A1;&#x7BA1;&#x7406;&#xFF0C;&#x65E0;&#x9700;&#x989D;&#x5916;&#x63A7;&#x5236;&#x4E8B;&#x52A1;&#x3002;</li>
<li>OXM &#x6A21;&#x5757;&#xFF1A;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x652F;&#x6301; Object /XML &#x6620;&#x5C04;&#x7684;&#x62BD;&#x8C61;&#x5C42;&#x5B9E;&#x73B0;&#xFF0C;&#x5982; JAXB&#x3001;Castor&#x3001;XMLBeans&#x3001;JiBX &#x548C; XStream&#x3002;&#x5C06; Java &#x5BF9;&#x8C61;&#x6620;&#x5C04;&#x6210; XML &#x6570;&#x636E;&#xFF0C;&#x6216;&#x8005;&#x5C06;XML &#x6570;&#x636E;&#x6620;&#x5C04;&#x6210; Java &#x5BF9;&#x8C61;&#x3002;</li>
<li>JMS &#x6A21;&#x5757;&#xFF1A;&#x6307; Java &#x6D88;&#x606F;&#x670D;&#x52A1;&#xFF0C;&#x63D0;&#x4F9B;&#x4E00;&#x5957; &#x201C;&#x6D88;&#x606F;&#x751F;&#x4EA7;&#x8005;&#x3001;&#x6D88;&#x606F;&#x6D88;&#x8D39;&#x8005;&#x201D;&#x6A21;&#x677F;&#x7528;&#x4E8E;&#x66F4;&#x52A0;&#x7B80;&#x5355;&#x7684;&#x4F7F;&#x7528; JMS&#xFF0C;JMS &#x7528;&#x4E8E;&#x7528;&#x4E8E;&#x5728;&#x4E24;&#x4E2A;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x4E4B;&#x95F4;&#xFF0C;&#x6216;&#x5206;&#x5E03;&#x5F0F;&#x7CFB;&#x7EDF;&#x4E2D;&#x53D1;&#x9001;&#x6D88;&#x606F;&#xFF0C;&#x8FDB;&#x884C;&#x5F02;&#x6B65;&#x901A;&#x4FE1;&#x3002;</li>
<li>Transactions &#x4E8B;&#x52A1;&#x6A21;&#x5757;&#xFF1A;&#x652F;&#x6301;&#x7F16;&#x7A0B;&#x548C;&#x58F0;&#x660E;&#x5F0F;&#x4E8B;&#x52A1;&#x7BA1;&#x7406;&#x3002;</li>
</ul>
<h3 id="2-web&#x6A21;&#x5757;">2. Web&#x6A21;&#x5757;</h3>
<p>Spring &#x7684; Web &#x5C42;&#x5305;&#x62EC; Web&#x3001;Servlet&#x3001;WebSocket &#x548C; Portlet &#x7EC4;&#x4EF6;&#xFF0C;&#x5177;&#x4F53;&#x4ECB;&#x7ECD;&#x5982;&#x4E0B;&#x3002;</p>
<ul>
<li>Web &#x6A21;&#x5757;&#xFF1A;&#x63D0;&#x4F9B;&#x4E86;&#x57FA;&#x672C;&#x7684; Web &#x5F00;&#x53D1;&#x96C6;&#x6210;&#x7279;&#x6027;&#xFF0C;&#x4F8B;&#x5982;&#x591A;&#x6587;&#x4EF6;&#x4E0A;&#x4F20;&#x529F;&#x80FD;&#x3001;&#x4F7F;&#x7528;&#x7684; Servlet &#x76D1;&#x542C;&#x5668;&#x7684; IOC &#x5BB9;&#x5668;&#x521D;&#x59CB;&#x5316;&#x4EE5;&#x53CA; Web &#x5E94;&#x7528;&#x4E0A;&#x4E0B;&#x6587;&#x3002;</li>
<li>Servlet &#x6A21;&#x5757;&#xFF1A;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A; Spring MVC Web &#x6846;&#x67B6;&#x5B9E;&#x73B0;&#x3002;Spring MVC &#x6846;&#x67B6;&#x63D0;&#x4F9B;&#x4E86;&#x57FA;&#x4E8E;&#x6CE8;&#x89E3;&#x7684;&#x8BF7;&#x6C42;&#x8D44;&#x6E90;&#x6CE8;&#x5165;&#x3001;&#x66F4;&#x7B80;&#x5355;&#x7684;&#x6570;&#x636E;&#x7ED1;&#x5B9A;&#x3001;&#x6570;&#x636E;&#x9A8C;&#x8BC1;&#x7B49;&#x53CA;&#x4E00;&#x5957;&#x975E;&#x5E38;&#x6613;&#x7528;&#x7684; JSP &#x6807;&#x7B7E;&#xFF0C;&#x5B8C;&#x5168;&#x65E0;&#x7F1D;&#x4E0E; Spring &#x5176;&#x4ED6;&#x6280;&#x672F;&#x534F;&#x4F5C;&#x3002;</li>
<li>WebSocket &#x6A21;&#x5757;&#xFF1A;&#x63D0;&#x4F9B;&#x4E86;&#x7B80;&#x5355;&#x7684;&#x63A5;&#x53E3;&#xFF0C;&#x7528;&#x6237;&#x53EA;&#x8981;&#x5B9E;&#x73B0;&#x54CD;&#x5E94;&#x7684;&#x63A5;&#x53E3;&#x5C31;&#x53EF;&#x4EE5;&#x5FEB;&#x901F;&#x7684;&#x642D;&#x5EFA; WebSocket Server&#xFF0C;&#x4ECE;&#x800C;&#x5B9E;&#x73B0;&#x53CC;&#x5411;&#x901A;&#x8BAF;&#x3002;</li>
<li>Portlet &#x6A21;&#x5757;&#xFF1A;&#x63D0;&#x4F9B;&#x4E86;&#x5728; Portlet &#x73AF;&#x5883;&#x4E2D;&#x4F7F;&#x7528; MVC &#x5B9E;&#x73B0;&#xFF0C;&#x7C7B;&#x4F3C; Web-Servlet &#x6A21;&#x5757;&#x7684;&#x529F;&#x80FD;&#x3002;</li>
</ul>
<h3 id="3-core-container&#xFF08;spring&#x7684;&#x6838;&#x5FC3;&#x5BB9;&#x5668;&#xFF09;">3. Core Container&#xFF08;Spring&#x7684;&#x6838;&#x5FC3;&#x5BB9;&#x5668;&#xFF09;</h3>
<p>Spring &#x7684;&#x6838;&#x5FC3;&#x5BB9;&#x5668;&#x662F;&#x5176;&#x4ED6;&#x6A21;&#x5757;&#x5EFA;&#x7ACB;&#x7684;&#x57FA;&#x7840;&#xFF0C;&#x7531; Beans &#x6A21;&#x5757;&#x3001;Core &#x6838;&#x5FC3;&#x6A21;&#x5757;&#x3001;Context &#x4E0A;&#x4E0B;&#x6587;&#x6A21;&#x5757;&#x548C; SpEL &#x8868;&#x8FBE;&#x5F0F;&#x8BED;&#x8A00;&#x6A21;&#x5757;&#x7EC4;&#x6210;&#xFF0C;&#x6CA1;&#x6709;&#x8FD9;&#x4E9B;&#x6838;&#x5FC3;&#x5BB9;&#x5668;&#xFF0C;&#x4E5F;&#x4E0D;&#x53EF;&#x80FD;&#x6709; AOP&#x3001;Web &#x7B49;&#x4E0A;&#x5C42;&#x7684;&#x529F;&#x80FD;&#x3002;&#x5177;&#x4F53;&#x4ECB;&#x7ECD;&#x5982;&#x4E0B;&#x3002;</p>
<ul>
<li>Beans &#x6A21;&#x5757;&#xFF1A;&#x63D0;&#x4F9B;&#x4E86;&#x6846;&#x67B6;&#x7684;&#x57FA;&#x7840;&#x90E8;&#x5206;&#xFF0C;&#x5305;&#x62EC;&#x63A7;&#x5236;&#x53CD;&#x8F6C;&#x548C;&#x4F9D;&#x8D56;&#x6CE8;&#x5165;&#x3002;</li>
<li>Core &#x6838;&#x5FC3;&#x6A21;&#x5757;&#xFF1A;&#x5C01;&#x88C5;&#x4E86; Spring &#x6846;&#x67B6;&#x7684;&#x5E95;&#x5C42;&#x90E8;&#x5206;&#xFF0C;&#x5305;&#x62EC;&#x8D44;&#x6E90;&#x8BBF;&#x95EE;&#x3001;&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x53CA;&#x4E00;&#x4E9B;&#x5E38;&#x7528;&#x5DE5;&#x5177;&#x7C7B;&#x3002;</li>
<li>Context &#x4E0A;&#x4E0B;&#x6587;&#x6A21;&#x5757;&#xFF1A;&#x5EFA;&#x7ACB;&#x5728; Core &#x548C; Beans &#x6A21;&#x5757;&#x7684;&#x57FA;&#x7840;&#x4E4B;&#x4E0A;&#xFF0C;&#x96C6;&#x6210; Beans &#x6A21;&#x5757;&#x529F;&#x80FD;&#x5E76;&#x6DFB;&#x52A0;&#x8D44;&#x6E90;&#x7ED1;&#x5B9A;&#x3001;&#x6570;&#x636E;&#x9A8C;&#x8BC1;&#x3001;&#x56FD;&#x9645;&#x5316;&#x3001;Java EE &#x652F;&#x6301;&#x3001;&#x5BB9;&#x5668;&#x751F;&#x547D;&#x5468;&#x671F;&#x3001;&#x4E8B;&#x4EF6;&#x4F20;&#x64AD;&#x7B49;&#x3002;ApplicationContext &#x63A5;&#x53E3;&#x662F;&#x4E0A;&#x4E0B;&#x6587;&#x6A21;&#x5757;&#x7684;&#x7126;&#x70B9;&#x3002;</li>
<li>SpEL &#x6A21;&#x5757;&#xFF1A;&#x63D0;&#x4F9B;&#x4E86;&#x5F3A;&#x5927;&#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x8BED;&#x8A00;&#x652F;&#x6301;&#xFF0C;&#x652F;&#x6301;&#x8BBF;&#x95EE;&#x548C;&#x4FEE;&#x6539;&#x5C5E;&#x6027;&#x503C;&#xFF0C;&#x65B9;&#x6CD5;&#x8C03;&#x7528;&#xFF0C;&#x652F;&#x6301;&#x8BBF;&#x95EE;&#x53CA;&#x4FEE;&#x6539;&#x6570;&#x7EC4;&#x3001;&#x5BB9;&#x5668;&#x548C;&#x7D22;&#x5F15;&#x5668;&#xFF0C;&#x547D;&#x540D;&#x53D8;&#x91CF;&#xFF0C;&#x652F;&#x6301;&#x7B97;&#x6570;&#x548C;&#x903B;&#x8F91;&#x8FD0;&#x7B97;&#xFF0C;&#x652F;&#x6301;&#x4ECE; Spring &#x5BB9;&#x5668;&#x83B7;&#x53D6; Bean&#xFF0C;&#x5B83;&#x4E5F;&#x652F;&#x6301;&#x5217;&#x8868;&#x6295;&#x5F71;&#x3001;&#x9009;&#x62E9;&#x548C;&#x4E00;&#x822C;&#x7684;&#x5217;&#x8868;&#x805A;&#x5408;&#x7B49;&#x3002;</li>
</ul>
<h3 id="4-aop&#x3001;aspects&#x3001;instrumentation&#x548C;messaging">4. AOP&#x3001;Aspects&#x3001;Instrumentation&#x548C;Messaging</h3>
<p>&#x5728; Core Container &#x4E4B;&#x4E0A;&#x662F; AOP&#x3001;Aspects &#x7B49;&#x6A21;&#x5757;&#xFF0C;&#x5177;&#x4F53;&#x4ECB;&#x7ECD;&#x5982;&#x4E0B;&#xFF1A;</p>
<ul>
<li>AOP &#x6A21;&#x5757;&#xFF1A;&#x63D0;&#x4F9B;&#x4E86;&#x9762;&#x5411;&#x5207;&#x9762;&#x7F16;&#x7A0B;&#x5B9E;&#x73B0;&#xFF0C;&#x63D0;&#x4F9B;&#x6BD4;&#x5982;&#x65E5;&#x5FD7;&#x8BB0;&#x5F55;&#x3001;&#x6743;&#x9650;&#x63A7;&#x5236;&#x3001;&#x6027;&#x80FD;&#x7EDF;&#x8BA1;&#x7B49;&#x901A;&#x7528;&#x529F;&#x80FD;&#x548C;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x5206;&#x79BB;&#x7684;&#x6280;&#x672F;&#xFF0C;&#x5E76;&#x4E14;&#x80FD;&#x52A8;&#x6001;&#x7684;&#x628A;&#x8FD9;&#x4E9B;&#x529F;&#x80FD;&#x6DFB;&#x52A0;&#x5230;&#x9700;&#x8981;&#x7684;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x8FD9;&#x6837;&#x5404;&#x53F8;&#x5176;&#x804C;&#xFF0C;&#x964D;&#x4F4E;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x548C;&#x901A;&#x7528;&#x529F;&#x80FD;&#x7684;&#x8026;&#x5408;&#x3002;</li>
<li>Aspects &#x6A21;&#x5757;&#xFF1A;&#x63D0;&#x4F9B;&#x4E0E; AspectJ &#x7684;&#x96C6;&#x6210;&#xFF0C;&#x662F;&#x4E00;&#x4E2A;&#x529F;&#x80FD;&#x5F3A;&#x5927;&#x4E14;&#x6210;&#x719F;&#x7684;&#x9762;&#x5411;&#x5207;&#x9762;&#x7F16;&#x7A0B;&#xFF08;AOP&#xFF09;&#x6846;&#x67B6;&#x3002;</li>
<li>Instrumentation &#x6A21;&#x5757;&#xFF1A;&#x63D0;&#x4F9B;&#x4E86;&#x7C7B;&#x5DE5;&#x5177;&#x7684;&#x652F;&#x6301;&#x548C;&#x7C7B;&#x52A0;&#x8F7D;&#x5668;&#x7684;&#x5B9E;&#x73B0;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x7279;&#x5B9A;&#x7684;&#x5E94;&#x7528;&#x670D;&#x52A1;&#x5668;&#x4E2D;&#x4F7F;&#x7528;&#x3002;</li>
<li>messaging &#x6A21;&#x5757;&#xFF1A;Spring 4.0 &#x4EE5;&#x540E;&#x65B0;&#x589E;&#x4E86;&#x6D88;&#x606F;&#xFF08;Spring-messaging&#xFF09;&#x6A21;&#x5757;&#xFF0C;&#x8BE5;&#x6A21;&#x5757;&#x63D0;&#x4F9B;&#x4E86;&#x5BF9;&#x6D88;&#x606F;&#x4F20;&#x9012;&#x4F53;&#x7CFB;&#x7ED3;&#x6784;&#x548C;&#x534F;&#x8BAE;&#x7684;&#x652F;&#x6301;&#x3002;</li>
</ul>
<h3 id="5-test&#x6A21;&#x5757;">5. Test&#x6A21;&#x5757;</h3>
<p>Test &#x6A21;&#x5757;&#xFF1A;Spring &#x652F;&#x6301; Junit &#x548C; TestNG &#x6D4B;&#x8BD5;&#x6846;&#x67B6;&#xFF0C;&#x800C;&#x4E14;&#x8FD8;&#x989D;&#x5916;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E9B;&#x57FA;&#x4E8E; Spring &#x7684;&#x6D4B;&#x8BD5;&#x529F;&#x80FD;&#xFF0C;&#x6BD4;&#x5982;&#x5728;&#x6D4B;&#x8BD5; Web &#x6846;&#x67B6;&#x65F6;&#xFF0C;&#x6A21;&#x62DF; Http &#x8BF7;&#x6C42;&#x7684;&#x529F;&#x80FD;&#x3002;</p>
<h2 id="spring&#x6846;&#x67B6;&#x7684;&#x6838;&#x5FC3;&#x4F5C;&#x7528;"><strong>spring&#x6846;&#x67B6;&#x7684;&#x6838;&#x5FC3;&#x4F5C;&#x7528;</strong></h2>
<p>spring&#x6846;&#x67B6;&#x7684;&#x6838;&#x5FC3;&#x4F5C;&#x7528;&#x662F;&#x7BA1;&#x7406;&#xFF08;&#x521B;&#x5EFA;&#xFF0C;&#x4F7F;&#x7528;&#xFF0C;&#x9500;&#x6BC1;&#xFF09;&#x9879;&#x76EE;&#x4E2D;&#x7684;&#x7EC4;&#x4EF6;&#x5BF9;&#x8C61;</p>
<h2 id="spring&#x5F00;&#x53D1;&#x73AF;&#x5883;&#x642D;&#x5EFA;">Spring&#x5F00;&#x53D1;&#x73AF;&#x5883;&#x642D;&#x5EFA;</h2>
<p>&#x4F7F;&#x7528; Spring &#x4E4B;&#x524D;&#x9700;&#x8981;&#x5B89;&#x88C5; JDK&#x3001;Tomcat &#x548C; Eclipse</p>
<p><strong>&#x4E0B;&#x8F7D;Apache Common Logging API</strong></p>
<p>Common Logging &#x662F;&#x4F7F;&#x7528; Spring &#x7684;&#x5FC5;&#x8981;&#x7EC4;&#x4EF6;&#x3002;Apache Common Logging API &#x4E0B;&#x8F7D;&#x5730;&#x5740;&#xFF1A;<a href="https://commons.apache.org/proper/commons-logging/download_logging.cgi" target="_blank">https://commons.apache.org/proper/commons-logging/download_logging.cgi</a></p>
<p>&#x4E0B;&#x8F7D;&#x5B8C;&#x6210;&#x540E;&#xFF0C;&#x5C06;&#x538B;&#x7F29;&#x5305;&#x89E3;&#x538B;&#x5230;&#x76F8;&#x5E94;&#x4F4D;&#x7F6E;&#x3002;&#x8BE5;&#x6587;&#x4EF6;&#x5305;&#x542B;&#x4EE5;&#x4E0B; jar &#x6587;&#x4EF6;&#x548C;&#x5176;&#x5B83;&#x652F;&#x6301;&#x6587;&#x6863;&#xFF0C;&#x76EE;&#x5F55;&#x7ED3;&#x6784;&#x5982;&#x4E0B;&#x3002;</p>
<p><img src="spring&#x6846;&#x67B6;.assets/10423R195-0.png" alt="Common Logging&#x76EE;&#x5F55;&#x7ED3;&#x6784;"></p>
<p><strong>&#x4E0B;&#x8F7D;Spring</strong></p>
<p>Spring &#x4E0B;&#x8F7D;&#x5730;&#x5740;&#xFF1A;<a href="https://repo.spring.io/ui/native/libs-release-local/org/springframework/spring/5.3.9/" target="_blank">https://repo.spring.io/ui/native/libs-release-local/org/springframework/spring/5.3.9/</a></p>
<p>&#x8BE5;&#x6587;&#x4EF6;&#x76EE;&#x5F55;&#x7ED3;&#x6784;&#x5982;&#x4E0B;&#xFF1A;</p>
<p><img src="spring&#x6846;&#x67B6;.assets/image-20210812211223645.png" alt="image-20210812211223645"></p>
<table>
<thead>
<tr>
<th>&#x540D;&#x79F0;</th>
<th>&#x4F5C;&#x7528;</th>
</tr>
</thead>
<tbody>
<tr>
<td>docs</td>
<td>&#x5305;&#x542B; Spring &#x7684; API &#x6587;&#x6863;&#x548C;&#x5F00;&#x53D1;&#x89C4;&#x8303;</td>
</tr>
<tr>
<td>libs</td>
<td>&#x5305;&#x542B;&#x5F00;&#x53D1;&#x9700;&#x8981;&#x7684; jar &#x5305;&#x548C;&#x6E90;&#x7801;&#x5305;</td>
</tr>
<tr>
<td>schema</td>
<td>&#x5305;&#x542B;&#x5F00;&#x53D1;&#x6240;&#x9700;&#x8981;&#x7684; schema &#x6587;&#x4EF6;&#xFF0C;&#x5728;&#x8FD9;&#x4E9B;&#x6587;&#x4EF6;&#x4E2D;&#x5B9A;&#x4E49;&#x4E86; Spring &#x76F8;&#x5173;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x7684;&#x7EA6;&#x675F;</td>
</tr>
</tbody>
</table>
<p>&#x5728; libs &#x76EE;&#x5F55;&#x4E2D;&#xFF0C;&#x5305;&#x542B;&#x4E86; Spring &#x6846;&#x67B6;&#x63D0;&#x4F9B;&#x7684;&#x6240;&#x6709; jar &#x6587;&#x4EF6;&#xFF0C;&#x5176;&#x4E2D;&#x6709; 4 &#x4E2A; jar &#x6587;&#x4EF6;&#x662F; Spring &#x6846;&#x67B6;&#x7684;&#x57FA;&#x7840;&#x5305;&#xFF0C;&#x5206;&#x522B;&#x5BF9;&#x5E94; Spring &#x5BB9;&#x5668;&#x7684;&#x56DB;&#x4E2A;&#x6A21;&#x5757;&#xFF0C;&#x5177;&#x4F53;&#x5982;&#x8868; 2 &#x6240;&#x793A;&#x3002;</p>
<table>
<thead>
<tr>
<th>&#x540D;&#x79F0;</th>
<th>&#x4F5C;&#x7528;</th>
</tr>
</thead>
<tbody>
<tr>
<td>spring-core-x.x.xx.RELEASE.jar</td>
<td>&#x5305;&#x542B; Spring &#x6846;&#x67B6;&#x57FA;&#x672C;&#x7684;&#x6838;&#x5FC3;&#x5DE5;&#x5177;&#x7C7B;&#xFF0C;Spring &#x5176;&#x4ED6;&#x7EC4;&#x4EF6;&#x90FD;&#x8981;&#x7528;&#x5230;&#x8FD9;&#x4E2A;&#x5305;&#x4E2D;&#x7684;&#x7C7B;&#xFF0C;&#x662F;&#x5176;&#x4ED6;&#x7EC4;&#x4EF6;&#x7684;&#x57FA;&#x672C;&#x6838;&#x5FC3;&#x3002;</td>
</tr>
<tr>
<td>spring-beans-x.x.xx.RELEASE.jar</td>
<td>&#x6240;&#x6709;&#x5E94;&#x7528;&#x90FD;&#x8981;&#x7528;&#x5230;&#x7684;&#xFF0C;&#x5B83;&#x5305;&#x542B;&#x8BBF;&#x95EE;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x3001;&#x521B;&#x5EFA;&#x548C;&#x7BA1;&#x7406; Bean &#x4EE5;&#x53CA;&#x8FDB;&#x884C; Inversion of Control&#xFF08;IoC&#xFF09;&#x6216;&#x8005; Dependency Injection&#xFF08;DI&#xFF09;&#x64CD;&#x4F5C;&#x76F8;&#x5173;&#x7684;&#x6240;&#x6709;&#x7C7B;&#x3002;</td>
</tr>
<tr>
<td>spring-context-x.x.xx.RELEASE.jar</td>
<td>Spring &#x63D0;&#x4F9B;&#x5728;&#x57FA;&#x7840; IoC &#x529F;&#x80FD;&#x4E0A;&#x7684;&#x6269;&#x5C55;&#x670D;&#x52A1;&#xFF0C;&#x6B64;&#x5916;&#x8FD8;&#x63D0;&#x4F9B;&#x8BB8;&#x591A;&#x4F01;&#x4E1A;&#x7EA7;&#x670D;&#x52A1;&#x7684;&#x652F;&#x6301;&#xFF0C;&#x5982;&#x90AE;&#x4EF6;&#x670D;&#x52A1;&#x3001;&#x4EFB;&#x52A1;&#x8C03;&#x5EA6;&#x3001;JNDI &#x5B9A;&#x4F4D;&#x3001;EJB &#x96C6;&#x6210;&#x3001;&#x8FDC;&#x7A0B;&#x8BBF;&#x95EE;&#x3001;&#x7F13;&#x5B58;&#x4EE5;&#x53CA;&#x5404;&#x79CD;&#x89C6;&#x56FE;&#x5C42;&#x6846;&#x67B6;&#x7684;&#x5C01;&#x88C5;&#x7B49;</td>
</tr>
<tr>
<td>spring-expression-x.x.xx.RELEASE.jar</td>
<td>&#x5B9A;&#x4E49;&#x4E86; Spring &#x7684;&#x8868;&#x8FBE;&#x5F0F;&#x8BED;&#x8A00;&#x3002; &#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF0C;&#x5728;&#x4F7F;&#x7528; Spring &#x5F00;&#x53D1;&#x65F6;&#xFF0C;&#x9664;&#x4E86; Spring &#x81EA;&#x5E26;&#x7684; JAR &#x5305;&#x4EE5;&#x5916;&#xFF0C;&#x8FD8;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x7B2C;&#x4E09;&#x65B9; JAR &#x5305; commons.logging &#x5904;&#x7406;&#x65E5;&#x5FD7;&#x4FE1;&#x606F;</td>
</tr>
</tbody>
</table>
<p>&#x4F7F;&#x7528; Spring &#x6846;&#x67B6;&#x65F6;&#xFF0C;&#x53EA;&#x9700;&#x5C06; Spring &#x7684; 4 &#x4E2A;&#x57FA;&#x7840;&#x5305;&#x4EE5;&#x53CA; commons-logging-1.2.jar &#x5305;&#x590D;&#x5236;&#x5230;&#x9879;&#x76EE;&#x7684; lib &#x76EE;&#x5F55;&#xFF0C;&#x5E76;&#x53D1;&#x5E03;&#x5230;&#x7C7B;&#x8DEF;&#x5F84;&#x4E2D;&#x5373;&#x53EF;</p>
<h2 id="&#x7B2C;&#x4E00;&#x4E2A;spring&#x7A0B;&#x5E8F;">&#x7B2C;&#x4E00;&#x4E2A;Spring&#x7A0B;&#x5E8F;</h2>
<p>1.&#x521B;&#x5EFA;maven&#x7684;javaweb&#x9879;&#x76EE;</p>
<p>2.&#x5F15;&#x5165;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span><span class="hljs-meta">?&gt;</span></span>
<span class="hljs-tag">&lt;<span class="hljs-name">beans</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/beans&quot;</span>
       <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
       <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd&quot;</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">beans</span>&gt;</span>
</code></pre>
<h2 id="spring&#x4E2D;ioc&#x548C;di">spring&#x4E2D;IOC&#x548C;DI</h2>
<p>IoC &#x5BB9;&#x5668;&#x662F; Spring &#x7684;&#x6838;&#x5FC3;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x79F0;&#x4E3A; Spring &#x5BB9;&#x5668;&#x3002;Spring &#x901A;&#x8FC7; IoC &#x5BB9;&#x5668;&#x6765;&#x7BA1;&#x7406;&#x5BF9;&#x8C61;&#x7684;&#x5B9E;&#x4F8B;&#x5316;&#x548C;&#x521D;&#x59CB;&#x5316;&#xFF0C;&#x4EE5;&#x53CA;&#x5BF9;&#x8C61;&#x4ECE;&#x521B;&#x5EFA;&#x5230;&#x9500;&#x6BC1;&#x7684;&#x6574;&#x4E2A;&#x751F;&#x547D;&#x5468;&#x671F;&#x3002;</p>
<p>Spring &#x4E2D;&#x4F7F;&#x7528;&#x7684;&#x5BF9;&#x8C61;&#x90FD;&#x7531; IoC &#x5BB9;&#x5668;&#x7BA1;&#x7406;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x6211;&#x4EEC;&#x624B;&#x52A8;&#x4F7F;&#x7528; new &#x8FD0;&#x7B97;&#x7B26;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#x3002;&#x7531; IoC &#x5BB9;&#x5668;&#x7BA1;&#x7406;&#x7684;&#x5BF9;&#x8C61;&#x79F0;&#x4E3A; Spring Bean&#xFF0C;Spring Bean &#x5C31;&#x662F; Java &#x5BF9;&#x8C61;&#xFF0C;&#x548C;&#x4F7F;&#x7528; new &#x8FD0;&#x7B97;&#x7B26;&#x521B;&#x5EFA;&#x7684;&#x5BF9;&#x8C61;&#x6CA1;&#x6709;&#x533A;&#x522B;&#x3002;</p>
<p>Spring &#x901A;&#x8FC7;&#x8BFB;&#x53D6; XML &#x6216; Java &#x6CE8;&#x89E3;&#x4E2D;&#x7684;&#x4FE1;&#x606F;&#x6765;&#x83B7;&#x53D6;&#x54EA;&#x4E9B;&#x5BF9;&#x8C61;&#x9700;&#x8981;&#x5B9E;&#x4F8B;&#x5316;&#x3002;Spring &#x63D0;&#x4F9B; 2 &#x79CD;&#x4E0D;&#x540C;&#x7C7B;&#x578B;&#x7684; IoC &#x5BB9;&#x5668;&#xFF0C;&#x5373; BeanFactory &#x548C; ApplicationContext &#x5BB9;&#x5668;</p>
<p><strong>1. BeanFactory &#x5BB9;&#x5668;</strong></p>
<p>BeanFactory &#x662F;&#x6700;&#x7B80;&#x5355;&#x7684;&#x5BB9;&#x5668;&#xFF0C;&#x7531; org.springframework.beans.factory.BeanFactory &#x63A5;&#x53E3;&#x5B9A;&#x4E49;&#xFF0C;&#x91C7;&#x7528;&#x61D2;&#x52A0;&#x8F7D;&#xFF08;lazy-load&#xFF09;&#xFF0C;&#x6240;&#x4EE5;&#x5BB9;&#x5668;&#x542F;&#x52A8;&#x6BD4;&#x8F83;&#x5FEB;&#x3002;BeanFactory &#x63D0;&#x4F9B;&#x4E86;&#x5BB9;&#x5668;&#x6700;&#x57FA;&#x672C;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x52A0;&#x8F7D;&#x65F6;&#x4E0D;&#x4F1A;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#xFF0C;&#x5728;&#x83B7;&#x53D6;bean&#x65F6;&#x624D;&#x4F1A;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;</p>
<p>&#x4E3A;&#x4E86;&#x80FD;&#x591F;&#x517C;&#x5BB9; Spring &#x96C6;&#x6210;&#x7684;&#x7B2C;&#x4E09;&#x65B9;&#x6846;&#x67B6;&#xFF08;&#x5982; BeanFactoryAware&#x3001;InitializingBean&#x3001;DisposableBean&#xFF09;&#xFF0C;&#x6240;&#x4EE5;&#x76EE;&#x524D;&#x4ECD;&#x7136;&#x4FDD;&#x7559;&#x4E86;&#x8BE5;&#x63A5;&#x53E3;&#x3002;&#x7B80;&#x5355;&#x6765;&#x8BF4;&#xFF0C;BeanFactory &#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x7BA1;&#x7406; Bean &#x7684;&#x5DE5;&#x5382;&#xFF0C;&#x5B83;&#x4E3B;&#x8981;&#x8D1F;&#x8D23;&#x521D;&#x59CB;&#x5316;&#x5404;&#x79CD; Bean&#xFF0C;&#x5E76;&#x8C03;&#x7528;&#x5B83;&#x4EEC;&#x7684;&#x751F;&#x547D;&#x5468;&#x671F;&#x65B9;&#x6CD5;&#x3002;BeanFactory &#x63A5;&#x53E3;&#x6709;&#x591A;&#x4E2A;&#x5B9E;&#x73B0;&#x7C7B; org.springframework.beans.factory.xml.XmlBeanFactory&#x6700;&#x5E38;&#x89C1;</p>
<p>&#x4F7F;&#x7528; BeanFactory &#x9700;&#x8981;&#x521B;&#x5EFA; XmlBeanFactory &#x7C7B;&#x7684;&#x5B9E;&#x4F8B;&#xFF0C;&#x901A;&#x8FC7; XmlBeanFactory &#x7C7B;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#x6765;&#x4F20;&#x9012; Resource &#x5BF9;&#x8C61;&#x3002;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<pre><code>Resource resource = new ClassPathResource(&quot;applicationContext.xml&quot;);
BeanFactory factory = new XmlBeanFactory(resource);
</code></pre><p><strong>2. ApplicationContext &#x5BB9;&#x5668;</strong></p>
<p>ApplicationContext &#x7EE7;&#x627F;&#x4E86; BeanFactory &#x63A5;&#x53E3;&#xFF0C;&#x7531; org.springframework.context.ApplicationContext &#x63A5;&#x53E3;&#x5B9A;&#x4E49;&#xFF0C;&#x5BF9;&#x8C61;&#x5728;&#x542F;&#x52A8;&#x5BB9;&#x5668;&#x65F6;&#x52A0;&#x8F7D;&#x3002;ApplicationContext &#x5728; BeanFactory &#x7684;&#x57FA;&#x7840;&#x4E0A;&#x589E;&#x52A0;&#x4E86;&#x5F88;&#x591A;&#x4F01;&#x4E1A;&#x7EA7;&#x529F;&#x80FD;&#xFF0C;&#x4F8B;&#x5982; AOP&#x3001;&#x56FD;&#x9645;&#x5316;&#x3001;&#x4E8B;&#x4EF6;&#x652F;&#x6301;&#x7B49;&#x3002;</p>
<p>ApplicationContext &#x63A5;&#x53E3;&#x6709;&#x4E24;&#x4E2A;&#x5E38;&#x7528;&#x7684;&#x5B9E;&#x73B0;&#x7C7B;&#xFF0C;&#x5177;&#x4F53;&#x5982;&#x4E0B;&#x3002;</p>
<p><strong>1&#xFF09;ClassPathXmlApplicationContext</strong></p>
<p>&#x8BE5;&#x7C7B;&#x4ECE;&#x7C7B;&#x8DEF;&#x5F84; ClassPath &#x4E2D;&#x5BFB;&#x627E;&#x6307;&#x5B9A;&#x7684; XML &#x914D;&#x7F6E;&#x6587;&#x4EF6;&#xFF0C;&#x5E76;&#x5B8C;&#x6210; ApplicationContext &#x7684;&#x5B9E;&#x4F8B;&#x5316;&#x5DE5;&#x4F5C;&#xFF0C;&#x5177;&#x4F53;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<pre><code>ApplicationContext applicationContext = new ClassPathXmlApplicationContext(String configLocation);
&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x52A0;&#x8F7D;&#xFF0C;&#x5219;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;
</code></pre><p>&#x5728;&#x4E0A;&#x8FF0;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;configLocation &#x53C2;&#x6570;&#x7528;&#x4E8E;&#x6307;&#x5B9A; Spring &#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x7684;&#x540D;&#x79F0;&#x548C;&#x4F4D;&#x7F6E;&#xFF0C;&#x5982; Beans.xml&#x3002;</p>
<p><strong>2&#xFF09;FileSystemXmlApplicationContext</strong></p>
<p>&#x8BE5;&#x7C7B;&#x4ECE;&#x6307;&#x5B9A;&#x7684;&#x6587;&#x4EF6;&#x7CFB;&#x7EDF;&#x8DEF;&#x5F84;&#x4E2D;&#x5BFB;&#x627E;&#x6307;&#x5B9A;&#x7684; XML &#x914D;&#x7F6E;&#x6587;&#x4EF6;&#xFF0C;&#x5E76;&#x5B8C;&#x6210; ApplicationContext &#x7684;&#x5B9E;&#x4F8B;&#x5316;&#x5DE5;&#x4F5C;&#xFF0C;&#x5177;&#x4F53;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<pre><code>ApplicationContext applicationContext = new FileSystemXmlApplicationContext(String configLocation);
</code></pre><p>&#x4E8C;&#x8005;&#x7684;&#x4E3B;&#x8981;&#x533A;&#x522B;&#x5728;&#x4E8E;&#xFF0C;&#x5982;&#x679C; Bean &#x7684;&#x67D0;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#x6CA1;&#x6709;&#x6CE8;&#x5165;&#xFF0C;&#x4F7F;&#x7528; BeanFacotry &#x52A0;&#x8F7D;&#x540E;&#xFF0C;&#x7B2C;&#x4E00;&#x6B21;&#x8C03;&#x7528; getBean() &#x65B9;&#x6CD5;&#x65F6;&#x4F1A;&#x629B;&#x51FA;&#x5F02;&#x5E38;&#xFF0C;&#x800C; ApplicationContext &#x5219;&#x4F1A;&#x5728;&#x521D;&#x59CB;&#x5316;&#x65F6;&#x81EA;&#x68C0;&#xFF0C;&#x8FD9;&#x6837;&#x6709;&#x5229;&#x4E8E;&#x68C0;&#x67E5;&#x6240;&#x4F9D;&#x8D56;&#x7684;&#x5C5E;&#x6027;&#x662F;&#x5426;&#x6CE8;&#x5165;&#x3002;</p>
<p>&#x56E0;&#x6B64;&#xFF0C;&#x5728;&#x5B9E;&#x9645;&#x5F00;&#x53D1;&#x4E2D;&#xFF0C;&#x901A;&#x5E38;&#x90FD;&#x9009;&#x62E9;&#x4F7F;&#x7528; ApplicationContext&#xFF0C;&#x53EA;&#x6709;&#x5728;&#x7CFB;&#x7EDF;&#x8D44;&#x6E90;&#x8F83;&#x5C11;&#x65F6;&#xFF0C;&#x624D;&#x8003;&#x8651;&#x4F7F;&#x7528; BeanFactory&#x3002;</p>
<blockquote>
<p><strong>spring&#x5BB9;&#x5668;&#x52A0;&#x8F7D;&#x591A;&#x4E2A;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</strong></p>
</blockquote>
<p>1.&#x4F7F;&#x7528;&#x5B57;&#x7B26;&#x4E32;&#x53C2;&#x6570;&#xFF0C;&#x9017;&#x53F7;&#x5206;&#x9694;</p>
<pre><code class="lang-java"><span class="hljs-comment">//&#x52A0;&#x8F7D;spring&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;  &#x542F;&#x52A8;spring&#x5BB9;&#x5668;</span>
ApplicationContext ac = <span class="hljs-keyword">new</span> ClassPathXmlApplicationContext(<span class="hljs-string">&quot;config/student.xml&quot;</span>,<span class="hljs-string">&quot;config/springConfig.xml&quot;</span>);
</code></pre>
<p>2.&#x4F7F;&#x7528;&#x5B57;&#x7B26;&#x4E32;&#x6570;&#x7EC4;</p>
<pre><code class="lang-java">String[] config = {<span class="hljs-string">&quot;config/student.xml&quot;</span>,<span class="hljs-string">&quot;config/springConfig.xml&quot;</span>};
 <span class="hljs-comment">//&#x52A0;&#x8F7D;spring&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;  &#x542F;&#x52A8;spring&#x5BB9;&#x5668;</span>
 ApplicationContext ac = <span class="hljs-keyword">new</span> ClassPathXmlApplicationContext(config);
</code></pre>
<p>3.&#x4F7F;&#x7528;&#x5BFC;&#x5165;</p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span><span class="hljs-meta">?&gt;</span></span>
<span class="hljs-tag">&lt;<span class="hljs-name">beans</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/beans&quot;</span>
       <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
       <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">import</span> <span class="hljs-attr">resource</span>=<span class="hljs-string">&quot;student.xml&quot;</span>/&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">import</span> <span class="hljs-attr">resource</span>=<span class="hljs-string">&quot;springConfig.xml&quot;</span>/&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">beans</span>&gt;</span>
</code></pre>
<pre><code class="lang-java"> <span class="hljs-comment">//&#x52A0;&#x8F7D;spring&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;  &#x542F;&#x52A8;spring&#x5BB9;&#x5668;</span>
   ApplicationContext ac = <span class="hljs-keyword">new</span> ClassPathXmlApplicationContext(<span class="hljs-string">&quot;config/applicationContext.xml&quot;</span>);
</code></pre>
<p><strong>Spring Bean&#x5B9A;&#x4E49;</strong></p>
<p>&#x7531; Spring IoC &#x5BB9;&#x5668;&#x7BA1;&#x7406;&#x7684;&#x5BF9;&#x8C61;&#x79F0;&#x4E3A; Bean&#xFF0C;Bean &#x6839;&#x636E; Spring &#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x4FE1;&#x606F;&#x521B;&#x5EFA;&#x3002;</p>
<p>&#x53EF;&#x4EE5;&#x628A; Spring IoC &#x5BB9;&#x5668;&#x770B;&#x4F5C;&#x662F;&#x4E00;&#x4E2A;&#x5927;&#x5DE5;&#x5382;&#xFF0C;Bean &#x76F8;&#x5F53;&#x4E8E;&#x5DE5;&#x5382;&#x7684;&#x4EA7;&#x54C1;&#xFF0C;&#x5982;&#x679C;&#x5E0C;&#x671B;&#x8FD9;&#x4E2A;&#x5927;&#x5DE5;&#x5382;&#x751F;&#x4EA7;&#x548C;&#x7BA1;&#x7406; Bean&#xFF0C;&#x5219;&#x9700;&#x8981;&#x544A;&#x8BC9;&#x5BB9;&#x5668;&#x9700;&#x8981;&#x54EA;&#x4E9B; Bean&#xFF0C;&#x4EE5;&#x53CA;&#x9700;&#x8981;&#x54EA;&#x79CD;&#x65B9;&#x5F0F;&#x88C5;&#x914D; Bean&#x3002;</p>
<p>Spring &#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x652F;&#x6301;&#x4E24;&#x79CD;&#x683C;&#x5F0F;&#xFF0C;&#x5373; XML &#x6587;&#x4EF6;&#x683C;&#x5F0F;&#x548C; Properties &#x6587;&#x4EF6;&#x683C;&#x5F0F;&#x3002;</p>
<ul>
<li>Properties &#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E3B;&#x8981;&#x4EE5; key-value &#x952E;&#x503C;&#x5BF9;&#x7684;&#x5F62;&#x5F0F;&#x5B58;&#x5728;&#xFF0C;&#x53EA;&#x80FD;&#x8D4B;&#x503C;&#xFF0C;&#x4E0D;&#x80FD;&#x8FDB;&#x884C;&#x5176;&#x4ED6;&#x64CD;&#x4F5C;&#xFF0C;&#x9002;&#x7528;&#x4E8E;&#x7B80;&#x5355;&#x7684;&#x5C5E;&#x6027;&#x914D;&#x7F6E;&#x3002;</li>
<li>XML &#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x662F;&#x6811;&#x5F62;&#x7ED3;&#x6784;&#xFF0C;&#x76F8;&#x5BF9;&#x4E8E; Properties &#x6587;&#x4EF6;&#x6765;&#x8BF4;&#x66F4;&#x52A0;&#x7075;&#x6D3B;&#x3002;XML &#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x7ED3;&#x6784;&#x6E05;&#x6670;&#xFF0C;&#x4F46;&#x662F;&#x5185;&#x5BB9;&#x6BD4;&#x8F83;&#x7E41;&#x7410;&#xFF0C;&#x9002;&#x7528;&#x4E8E;&#x5927;&#x578B;&#x590D;&#x6742;&#x7684;&#x9879;&#x76EE;&#x3002;</li>
</ul>
<p>&#x901A;&#x5E38;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;Spring &#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4F7F;&#x7528; XML &#x683C;&#x5F0F;&#x3002;XML &#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x7684;&#x6839;&#x5143;&#x7D20;&#x662F; <beans>&#xFF0C;&#x8BE5;&#x5143;&#x7D20;&#x5305;&#x542B;&#x4E86;&#x591A;&#x4E2A;&#x5B50;&#x5143;&#x7D20; <bean>&#x3002;&#x6BCF;&#x4E00;&#x4E2A; <bean> &#x5143;&#x7D20;&#x90FD;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A; Bean&#xFF0C;&#x5E76;&#x63CF;&#x8FF0;&#x4E86;&#x8BE5; Bean &#x5982;&#x4F55;&#x88AB;&#x88C5;&#x914D;&#x5230; Spring &#x5BB9;&#x5668;&#x4E2D;<bean> &#x5143;&#x7D20;&#x4E2D;&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x5F88;&#x591A;&#x5C5E;&#x6027;&#xFF0C;&#x5176;&#x5E38;&#x7528;&#x5C5E;&#x6027;&#x5982;&#x4E0B;&#x8868;&#x6240;&#x793A;&#x3002;</bean></bean></bean></beans></p>
<table>
<thead>
<tr>
<th>&#x5C5E;&#x6027;&#x540D;&#x79F0;</th>
<th>&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td>id</td>
<td>Bean &#x7684;&#x552F;&#x4E00;&#x6807;&#x8BC6;&#x7B26;&#xFF0C;Spring &#x5BB9;&#x5668;&#x5BF9; Bean &#x7684;&#x914D;&#x7F6E;&#x548C;&#x7BA1;&#x7406;&#x90FD;&#x901A;&#x8FC7;&#x8BE5;&#x5C5E;&#x6027;&#x5B8C;&#x6210;&#x3002;id &#x7684;&#x503C;&#x5FC5;&#x987B;&#x4EE5;&#x5B57;&#x6BCD;&#x5F00;&#x59CB;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x5B57;&#x6BCD;&#x3001;&#x6570;&#x5B57;&#x3001;&#x4E0B;&#x5212;&#x7EBF;&#x7B49;&#x7B26;&#x53F7;&#x3002;</td>
</tr>
<tr>
<td>name</td>
<td>name &#x5C5E;&#x6027;&#x4E2D;&#x53EF;&#x4EE5;&#x4E3A; Bean &#x6307;&#x5B9A;&#x591A;&#x4E2A;&#x540D;&#x79F0;&#xFF0C;&#x6BCF;&#x4E2A;&#x540D;&#x79F0;&#x4E4B;&#x95F4;&#x7528;&#x9017;&#x53F7;&#x6216;&#x5206;&#x53F7;&#x9694;&#x5F00;&#x3002;Spring &#x5BB9;&#x5668;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; name &#x5C5E;&#x6027;&#x914D;&#x7F6E;&#x548C;&#x7BA1;&#x7406;&#x5BB9;&#x5668;&#x4E2D;&#x7684; Bean&#x3002;</td>
</tr>
<tr>
<td>class</td>
<td>&#x8BE5;&#x5C5E;&#x6027;&#x6307;&#x5B9A;&#x4E86; Bean &#x7684;&#x5177;&#x4F53;&#x5B9E;&#x73B0;&#x7C7B;&#xFF0C;&#x5B83;&#x5FC5;&#x987B;&#x662F;&#x4E00;&#x4E2A;&#x5B8C;&#x6574;&#x7684;&#x7C7B;&#x540D;&#xFF0C;&#x5373;&#x7C7B;&#x7684;&#x5168;&#x9650;&#x5B9A;&#x540D;&#x3002;</td>
</tr>
<tr>
<td>scope</td>
<td>&#x7528;&#x4E8E;&#x8BBE;&#x5B9A; Bean &#x5B9E;&#x4F8B;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x5C5E;&#x6027;&#x503C;&#x53EF;&#x4EE5;&#x4E3A; singleton&#xFF08;&#x5355;&#x4F8B;&#xFF09;&#x3001;prototype&#xFF08;&#x539F;&#x578B;&#xFF09;&#x3001;request&#x3001;session &#x548C; global Session&#x3002;&#x5176;&#x9ED8;&#x8BA4;&#x503C;&#x662F; singleton</td>
</tr>
<tr>
<td>constructor-arg</td>
<td><bean>&#x5143;&#x7D20;&#x7684;&#x5B50;&#x5143;&#x7D20;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x6B64;&#x5143;&#x7D20;&#x4F20;&#x5165;&#x6784;&#x9020;&#x53C2;&#x6570;&#x8FDB;&#x884C;&#x5B9E;&#x4F8B;&#x5316;&#x3002;&#x8BE5;&#x5143;&#x7D20;&#x7684; index &#x5C5E;&#x6027;&#x6307;&#x5B9A;&#x6784;&#x9020;&#x53C2;&#x6570;&#x7684;&#x5E8F;&#x53F7;&#xFF08;&#x4ECE; 0 &#x5F00;&#x59CB;&#xFF09;&#xFF0C;type &#x5C5E;&#x6027;&#x6307;&#x5B9A;&#x6784;&#x9020;&#x53C2;&#x6570;&#x7684;&#x7C7B;&#x578B;</bean></td>
</tr>
<tr>
<td>property</td>
<td><bean>&#x5143;&#x7D20;&#x7684;&#x5B50;&#x5143;&#x7D20;&#xFF0C;&#x7528;&#x4E8E;&#x8C03;&#x7528; Bean &#x5B9E;&#x4F8B;&#x4E2D;&#x7684; setter &#x65B9;&#x6CD5;&#x6765;&#x5C5E;&#x6027;&#x8D4B;&#x503C;&#xFF0C;&#x4ECE;&#x800C;&#x5B8C;&#x6210;&#x4F9D;&#x8D56;&#x6CE8;&#x5165;&#x3002;&#x8BE5;&#x5143;&#x7D20;&#x7684; name &#x5C5E;&#x6027;&#x7528;&#x4E8E;&#x6307;&#x5B9A; Bean &#x5B9E;&#x4F8B;&#x4E2D;&#x76F8;&#x5E94;&#x7684;&#x5C5E;&#x6027;&#x540D;</bean></td>
</tr>
<tr>
<td>ref</td>
<td><property> &#x548C; <constructor-arg> &#x7B49;&#x5143;&#x7D20;&#x7684;&#x5B50;&#x5143;&#x7D22;&#xFF0C;&#x8BE5;&#x5143;&#x7D20;&#x4E2D;&#x7684; bean &#x5C5E;&#x6027;&#x7528;&#x4E8E;&#x6307;&#x5B9A;&#x5BF9;&#x67D0;&#x4E2A; Bean &#x5B9E;&#x4F8B;&#x7684;&#x5F15;&#x7528;</constructor-arg></property></td>
</tr>
<tr>
<td>value</td>
<td><property> &#x548C; <constractor-arg> &#x7B49;&#x5143;&#x7D20;&#x7684;&#x5B50;&#x5143;&#x7D20;&#xFF0C;&#x7528;&#x4E8E;&#x76F4;&#x63A5;&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x5E38;&#x91CF;&#x503C;</constractor-arg></property></td>
</tr>
<tr>
<td>list</td>
<td>&#x7528;&#x4E8E;&#x5C01;&#x88C5; List &#x6216;&#x6570;&#x7EC4;&#x7C7B;&#x578B;&#x7684;&#x4F9D;&#x8D56;&#x6CE8;&#x5165;</td>
</tr>
<tr>
<td>set</td>
<td>&#x7528;&#x4E8E;&#x5C01;&#x88C5; Set &#x7C7B;&#x578B;&#x7684;&#x4F9D;&#x8D56;&#x6CE8;&#x5165;</td>
</tr>
<tr>
<td>map</td>
<td>&#x7528;&#x4E8E;&#x5C01;&#x88C5; Map &#x7C7B;&#x578B;&#x7684;&#x4F9D;&#x8D56;&#x6CE8;&#x5165;</td>
</tr>
<tr>
<td>entry</td>
<td><map> &#x5143;&#x7D20;&#x7684;&#x5B50;&#x5143;&#x7D20;&#xFF0C;&#x7528;&#x4E8E;&#x8BBE;&#x7F6E;&#x4E00;&#x4E2A;&#x952E;&#x503C;&#x5BF9;&#x3002;&#x5176; key &#x5C5E;&#x6027;&#x6307;&#x5B9A;&#x5B57;&#x7B26;&#x4E32;&#x7C7B;&#x578B;&#x7684;&#x952E;&#x503C;&#xFF0C;ref &#x6216; value &#x5B50;&#x5143;&#x7D20;&#x6307;&#x5B9A;&#x5176;&#x503C;</map></td>
</tr>
<tr>
<td>init-method</td>
<td>&#x5BB9;&#x5668;&#x52A0;&#x8F7D; Bean &#x65F6;&#x8C03;&#x7528;&#x8BE5;&#x65B9;&#x6CD5;&#xFF0C;&#x7C7B;&#x4F3C;&#x4E8E; Servlet &#x4E2D;&#x7684; init() &#x65B9;&#x6CD5;</td>
</tr>
<tr>
<td>destroy-method</td>
<td>&#x5BB9;&#x5668;&#x5220;&#x9664; Bean &#x65F6;&#x8C03;&#x7528;&#x8BE5;&#x65B9;&#x6CD5;&#xFF0C;&#x7C7B;&#x4F3C;&#x4E8E; Servlet &#x4E2D;&#x7684; destroy() &#x65B9;&#x6CD5;&#x3002;&#x8BE5;&#x65B9;&#x6CD5;&#x53EA;&#x5728; scope=singleton &#x65F6;&#x6709;&#x6548;</td>
</tr>
<tr>
<td>lazy-init</td>
<td>&#x61D2;&#x52A0;&#x8F7D;&#xFF0C;&#x503C;&#x4E3A; true&#xFF0C;&#x5BB9;&#x5668;&#x5728;&#x9996;&#x6B21;&#x8BF7;&#x6C42;&#x65F6;&#x624D;&#x4F1A;&#x521B;&#x5EFA; Bean &#x5B9E;&#x4F8B;&#xFF1B;&#x503C;&#x4E3A; false&#xFF0C;&#x5BB9;&#x5668;&#x5728;&#x542F;&#x52A8;&#x65F6;&#x521B;&#x5EFA; Bean &#x5B9E;&#x4F8B;&#x3002;&#x8BE5;&#x65B9;&#x6CD5;&#x53EA;&#x5728; scope=singleton &#x65F6;&#x6709;&#x6548;</td>
</tr>
</tbody>
</table>
<p><strong>IOC&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x5F0F;</strong></p>
<p>1.&#x65E0;&#x53C2;&#x6784;&#x9020;&#x5668;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;   &#xFF08;&#x9ED8;&#x8BA4;&#xFF09;</p>
<p>2.&#x6709;&#x53C2;&#x6784;&#x9020;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;</p>
<ul>
<li>&#x4F7F;&#x7528;&#x4E0B;&#x6807;&#x4F20;&#x9012;&#x53C2;&#x6570;</li>
</ul>
<pre><code class="lang-java"> &lt;!--    &#x4F7F;&#x7528;&#x7D22;&#x5F15;&#x5339;&#x914D;&#x53C2;&#x6570;--&gt;
&lt;bean id=&quot;student&quot; class=&quot;cn.kgc.spring.entity.Student&quot;&gt;
    &lt;constructor-arg index=&quot;0&quot; value=&quot;20&quot;/&gt;
    &lt;constructor-arg index=&quot;1&quot; value=&quot;&#x674E;&#x56DB;&quot;/&gt;
    &lt;constructor-arg index=&quot;2&quot; value=&quot;20210814&quot;/&gt;
    &lt;constructor-arg index=&quot;3&quot; value=&quot;2021/08/14&quot;/&gt;
&lt;/bean&gt;
</code></pre>
<ul>
<li>&#x4F7F;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x4F20;&#x9012;&#x53C2;&#x6570;</li>
</ul>
<pre><code class="lang-java">&lt;!--&#x4F7F;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x5339;&#x914D;&#x53C2;&#x6570;  &#x6709;&#x76F8;&#x540C;&#x7684;&#x53C2;&#x6570;&#x7C7B;&#x578B;&#x53EF;&#x914D;&#x5408;&#x7D22;&#x5F15;&#x4E00;&#x8D77;&#x4F7F;&#x7528;--&gt;
 &lt;bean id=&quot;student&quot; class=&quot;cn.kgc.spring.entity.Student&quot;&gt;
        &lt;constructor-arg type=&quot;int&quot; value=&quot;20&quot;/&gt;
        &lt;constructor-arg type=&quot;java.lang.String&quot; index=&quot;1&quot; value=&quot;&#x674E;&#x56DB;&quot;/&gt;
        &lt;constructor-arg type=&quot;java.lang.String&quot;  value=&quot;20210814&quot;/&gt;
        &lt;constructor-arg type=&quot;java.util.Date&quot; value=&quot;2021/08/14&quot;/&gt;
 &lt;/bean&gt;
</code></pre>
<ul>
<li>&#x901A;&#x8FC7;&#x5C5E;&#x6027;&#x540D;&#x4F20;&#x9012;&#x53C2;&#x6570;</li>
</ul>
<pre><code class="lang-java">&lt;!--&#x4F7F;&#x7528;&#x5C5E;&#x6027;&#x540D;&#x8D4B;&#x503C;--&gt;
    &lt;bean id=&quot;student&quot; class=&quot;cn.kgc.spring.entity.Student&quot;&gt;
        &lt;constructor-arg  name=&quot;age&quot; value=&quot;20&quot;/&gt;
        &lt;constructor-arg  name=&quot;name&quot; value=&quot;&#x674E;&#x56DB;&quot;/&gt;
        &lt;constructor-arg   name=&quot;stuNo&quot; value=&quot;20210814&quot;/&gt;
        &lt;constructor-arg   name=&quot;birth&quot; value=&quot;2021/08/14&quot; /&gt;
    &lt;/bean&gt;
</code></pre>
<p><strong>&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#x65F6;&#x5C5E;&#x6027;&#x7684;&#x5176;&#x5B83;&#x6CE8;&#x5165;&#x65B9;&#x5F0F;</strong></p>
<p><strong>set&#x6CE8;&#x5165;</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;studentService&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;cn.kgc.spring.service.StudentServiceImpl&quot;</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x5C5E;&#x6027;&#x662F;&#x5F15;&#x7528;&#x7C7B;&#x578B; &#x8D4B;&#x503C;&#x65F6;&#x4F7F;&#x7528;ref--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;studentDao&quot;</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;studentDao&quot;</span>/&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x5C5E;&#x6027;&#x662F;&#x57FA;&#x672C;&#x7C7B;&#x578B; String&#x7C7B;&#x578B; Date&#x7C7B;&#x578B; &#x8D4B;&#x503C;&#x65F6;&#x4F7F;&#x7528;value --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;age&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;20&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;stuName&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;&#x5F20;&#x4E09;&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;price&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;20.4&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;score&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;80.3&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;birth&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;2021/8/13&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;str&quot;</span> &gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">array</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>&#x5F20;&#x4E09;<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>&#x674E;&#x56DB;<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>&#x738B;&#x4E94;<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">array</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;lis&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">list</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>&#x62BD;&#x70DF;<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>&#x559D;&#x9152;<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>&#x70EB;&#x5934;<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">list</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
        <span class="hljs-comment">&lt;!-- spring&#x5BB9;&#x5668;&#x4E2D;&#x7EC4;&#x4EF6;&#x9ED8;&#x8BA4;&#x90FD;&#x662F;&#x5355;&#x4F8B;&#x7684; &#x5168;&#x5C40;&#x5171;&#x4EAB;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;--&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;lis2&quot;</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">list</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">ref</span> <span class="hljs-attr">bean</span>=<span class="hljs-string">&quot;studentDao&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">ref</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">ref</span> <span class="hljs-attr">bean</span>=<span class="hljs-string">&quot;studentDao&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">ref</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">ref</span> <span class="hljs-attr">bean</span>=<span class="hljs-string">&quot;studentDao&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">ref</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">list</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;books&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">set</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>java<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>php<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>c#<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">set</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;scores&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">map</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">entry</span> <span class="hljs-attr">key</span>=<span class="hljs-string">&quot;math&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;89&quot;</span> &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">entry</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">entry</span> <span class="hljs-attr">key</span>=<span class="hljs-string">&quot;english&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;90&quot;</span> &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">entry</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">entry</span> <span class="hljs-attr">key</span>=<span class="hljs-string">&quot;java&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;80&quot;</span> &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">entry</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">map</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;map&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">map</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">entry</span> <span class="hljs-attr">key</span>=<span class="hljs-string">&quot;01&quot;</span> <span class="hljs-attr">value-ref</span>=<span class="hljs-string">&quot;studentDao&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">entry</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">entry</span> <span class="hljs-attr">key</span>=<span class="hljs-string">&quot;02&quot;</span> <span class="hljs-attr">value-ref</span>=<span class="hljs-string">&quot;studentDao&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">entry</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">entry</span> <span class="hljs-attr">key</span>=<span class="hljs-string">&quot;03&quot;</span> <span class="hljs-attr">value-ref</span>=<span class="hljs-string">&quot;studentDao&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">entry</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">map</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;ps&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">props</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">prop</span> <span class="hljs-attr">key</span>=<span class="hljs-string">&quot;driver&quot;</span>&gt;</span>com.mysql.jdbc.Driver<span class="hljs-tag">&lt;/<span class="hljs-name">prop</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">prop</span> <span class="hljs-attr">key</span>=<span class="hljs-string">&quot;url&quot;</span>&gt;</span>jdbc:mysql:///mybatis<span class="hljs-tag">&lt;/<span class="hljs-name">prop</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">prop</span> <span class="hljs-attr">key</span>=<span class="hljs-string">&quot;username&quot;</span>&gt;</span>root<span class="hljs-tag">&lt;/<span class="hljs-name">prop</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">prop</span> <span class="hljs-attr">key</span>=<span class="hljs-string">&quot;password&quot;</span>&gt;</span>rooot<span class="hljs-tag">&lt;/<span class="hljs-name">prop</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">props</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
</code></pre>
<p>&#x4F7F;&#x7528;set&#x6CE8;&#x5165;&#xFF0C;&#x6BCF;&#x4E2A;&#x5C5E;&#x6027;&#x5FC5;&#x987B;&#x542B;&#x6709;&#x5BF9;&#x5E94;&#x7684;set&#x65B9;&#x6CD5;&#xFF0C;&#x5426;&#x5219;&#x65E0;&#x6CD5;&#x8FDB;&#x884C;&#x5C5E;&#x6027;&#x7684;&#x6CE8;&#x5165;</p>
<blockquote>
<p><strong>Spring&#x7684;&#x4F9D;&#x8D56;&#x6CE8;&#x5165;&#x4E4B;p&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x548C;c&#x547D;&#x540D;&#x7A7A;&#x95F4;</strong></p>
</blockquote>
<p>p&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x662F;set&#x6CE8;&#x5165;&#x7684;&#x4E00;&#x79CD;&#x5FEB;&#x6377;&#x5B9E;&#x73B0;&#x65B9;&#x5F0F;&#xFF0C;&#x60F3;&#x8981;&#x4F7F;&#x7528;p&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x6CE8;&#x5165;&#xFF0C;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x4E00;&#x4E0B;&#x51E0;&#x70B9;&#x3002;</p>
<ol>
<li><p>&#x5B9E;&#x4F53;&#x7C7B;&#x4E2D;&#x5FC5;&#x987B;&#x6709;set&#x65B9;&#x6CD5;&#xFF1B;</p>
</li>
<li><p>&#x5B9E;&#x4F53;&#x7C7B;&#x4E2D;&#x5FC5;&#x987B;&#x6709;&#x65E0;&#x53C2;&#x6784;&#x9020;&#x5668;&#xFF08;&#x9ED8;&#x8BA4;&#x5B58;&#x5728;&#xFF09;&#xFF1B;</p>
</li>
<li><p>&#x5FC5;&#x987B;&#x5BFC;&#x5165;p&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x6CE8;&#x5165;&#x65B9;&#x5F0F;&#x4F9D;&#x8D56;&#x3002;</p>
</li>
</ol>
<p>xml&#x4F9D;&#x8D56;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code>xmlns:p=&quot;http://www.springframework.org/schema/p&quot;
</code></pre><p>&#x5BFC;&#x5165;&#x540E;&#x5373;&#x53EF;&#x4F7F;&#x7528;</p>
<pre><code>&lt;bean id=&quot;user&quot; class=&quot;com.yd.pojo.User&quot; p:age=&quot;18&quot; p:name=&quot;&#x8001;&#x738B;&quot;/&gt;
&lt;!--&#x9700;&#x8981;&#x6709;&#x5C5E;&#x6027;&#x7684;set&#x65B9;&#x6CD5;--&gt;
&lt;bean id=&quot;student&quot; class=&quot;cn.kgc.spring.entity.Student&quot; p:age=&quot;20&quot; p:name=&quot;lisi&quot; p:birth=&quot;2021/1/1&quot; p:stuNo=&quot;20210814001&quot;&gt;&lt;/bean&gt;
</code></pre><p>c&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x662F;&#x6784;&#x9020;&#x5668;&#x6CE8;&#x5165;&#x7684;&#x4E00;&#x79CD;&#x5FEB;&#x6377;&#x5B9E;&#x73B0;&#x65B9;&#x5F0F;&#xFF0C;&#x60F3;&#x8981;&#x4F7F;&#x7528;c&#x547D;&#x540D;&#x7A7A;&#x95F4;&#xFF0C;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x4E00;&#x4E0B;&#x51E0;&#x70B9;&#x3002;</p>
<ol>
<li><p>&#x5B9E;&#x4F53;&#x7C7B;&#x4E2D;&#x5FC5;&#x987B;&#x5B58;&#x5728;&#x6709;&#x53C2;&#x6784;&#x9020;&#x5668;&#xFF1B;</p>
</li>
<li><p>&#x5FC5;&#x987B;&#x5BFC;&#x5165;c&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x6CE8;&#x5165;&#x65B9;&#x5F0F;&#x4F9D;&#x8D56;&#x3002;</p>
</li>
</ol>
<p>xml&#x4F9D;&#x8D56;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code>xmlns:c=&quot;http://www.springframework.org/schema/c&quot;
</code></pre><p>&#x5BFC;&#x5165;&#x540E;&#x5373;&#x53EF;&#x4F7F;&#x7528;</p>
<pre><code>&lt;bean id=&quot;user2&quot; class=&quot;com.yd.pojo.User&quot; c:age=&quot;23&quot; c:name=&quot;&#x4E2D;&#x738B;&quot;/&gt;
</code></pre><pre><code class="lang-java">&lt;!--&#x9700;&#x8981;&#x6709;&#x6709;&#x53C2;&#x6784;&#x9020;&#x65B9;&#x6CD5;--&gt;
&lt;bean id=&quot;student&quot; class=&quot;cn.kgc.spring.entity.Student&quot; c:age=&quot;30&quot; c:name=&quot;&#x738B;&#x4E94;&quot; c:birth=&quot;1991/12/08&quot; c:stuNo=&quot;20210814001&quot;&gt;&lt;/bean&gt;
</code></pre>
<h2 id="&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x5668;&#x7684;&#x4F7F;&#x7528;&#xFF1A;">&#x7C7B;&#x578B;&#x8F6C;&#x6362;&#x5668;&#x7684;&#x4F7F;&#x7528;&#xFF1A;</h2>
<p>&#x4F5C;&#x7528;&#xFF1A;&#x81EA;&#x5B9A;&#x4E49;&#x6CE8;&#x5165;&#x53C2;&#x6570;&#x548C;&#x5B9E;&#x4F53;&#x7C7B;&#x4E2D;&#x7C7B;&#x578B;&#x7684;&#x5339;&#x914D;&#x65B9;&#x5F0F;</p>
<pre><code class="lang-java"><span class="hljs-keyword">import</span> org.springframework.core.convert.converter.Converter;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyConverter</span>  <span class="hljs-keyword">implements</span> <span class="hljs-title">Converter</span>&lt;<span class="hljs-title">String</span>, <span class="hljs-title">Date</span>&gt; </span>{

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> Date <span class="hljs-title">convert</span><span class="hljs-params">(String source)</span> </span>{
        SimpleDateFormat simpleDateFormat = <span class="hljs-keyword">new</span> SimpleDateFormat(<span class="hljs-string">&quot;yyyy-MM-dd&quot;</span>);
        <span class="hljs-keyword">try</span> {
            Date parse = simpleDateFormat.parse(source);
            <span class="hljs-keyword">return</span> parse;
        } <span class="hljs-keyword">catch</span> (ParseException e) {
            e.printStackTrace();
        }
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
    }
}
</code></pre>
<p>xml&#x6587;&#x4EF6;&#x914D;&#x7F6E;&#xFF1A;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;convert&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;cn.kgc.spring.basic.convert.MyConverter&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;conversionService&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;org.springframework.context.support.ConversionServiceFactoryBean&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;converters&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">set</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">ref</span> <span class="hljs-attr">bean</span>=<span class="hljs-string">&quot;convert&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">ref</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">set</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
</code></pre>
<h2 id="bean&#x7684;&#x81EA;&#x52A8;&#x88C5;&#x914D;"><strong>Bean&#x7684;&#x81EA;&#x52A8;&#x88C5;&#x914D;</strong></h2>
<p><strong>1.autowire=&quot;byName&quot;&#x5728;&#x5BB9;&#x5668;&#x7684;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x5BFB;&#x627E;&#x4E0E;&#x7C7B;&#x4E2D;&#x5C5E;&#x6027;&#x5BF9;&#x5E94;&#x7684;set&#x65B9;&#x6CD5;&#x540D;&#x5B57;&#x76F8;&#x540C;&#x7684;id&#x5C5E;&#x6027;&#x503C;&#x8FDB;&#x884C;&#x88C5;&#x914D;</strong></p>
<pre><code class="lang-xml">     <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;teacher&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;cn.kgc.spring.entity.Teacher&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;name&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;&#x674E;&#x8001;&#x5E08;&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;teaNo&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;001&quot;</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;classRoom1&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;cn.kgc.spring.entity.ClassRoom&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;address&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;&#x5B66;&#x601D;&#x697C;1&#x697C;&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;classNo&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;1&quot;</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;student&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;cn.kgc.spring.entity.Student&quot;</span> <span class="hljs-attr">autowire</span>=<span class="hljs-string">&quot;byName&quot;</span> &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
</code></pre>
<p><strong>2.autowire=&quot;byType&quot;&#x5728;&#x5BB9;&#x5668;&#x7684;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x5BFB;&#x627E;&#x4E0E;&#x7C7B;&#x4E2D;&#x5C5E;&#x6027;&#x7C7B;&#x578B;&#x76F8;&#x540C;&#x7684;Bean&#x8FDB;&#x884C;&#x88C5;&#x914D;</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;teacher&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;cn.kgc.spring.entity.Teacher&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;name&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;&#x674E;&#x8001;&#x5E08;&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;teaNo&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;001&quot;</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;classRoom1&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;cn.kgc.spring.entity.ClassRoom&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;address&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;&#x5B66;&#x601D;&#x697C;1&#x697C;&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;classNo&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;1&quot;</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;student&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;cn.kgc.spring.entity.Student&quot;</span> <span class="hljs-attr">autowire</span>=<span class="hljs-string">&quot;byType&quot;</span> &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
</code></pre>
<p><strong>3.&#x4F7F;&#x7528;&#x6CE8;&#x89E3;&#x81EA;&#x52A8;&#x88C5;&#x914D;</strong></p>
<p>1.&#x5BFC;&#x5165;context&#x7EA6;&#x675F;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">beans</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/beans&quot;</span>
       <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
       <span class="hljs-attr">xmlns:p</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/p&quot;</span>
       <span class="hljs-attr">xmlns:c</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/c&quot;</span>
       <span class="hljs-attr">xmlns:context</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/context&quot;</span>
       <span class="hljs-attr">xsi:schemaLocation</span>=
               &quot;<span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">beans</span>
                <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">beans</span>/<span class="hljs-attr">spring-beans.xsd</span>
                <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">context</span>
                <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">context</span>/<span class="hljs-attr">spring-context.xsd</span>&quot; &gt;</span>
</code></pre>
<p>2.&#x5F00;&#x542F;&#x6CE8;&#x89E3;&#x652F;&#x6301;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">context:annotation-config</span>/&gt;</span>
</code></pre>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Student</span> </span>{

    <span class="hljs-meta">@Value</span>(<span class="hljs-string">&quot;2021&quot;</span>)
    <span class="hljs-keyword">private</span> String stuNo;
    <span class="hljs-meta">@Value</span>(<span class="hljs-string">&quot;wangwu&quot;</span>)
    <span class="hljs-keyword">private</span> String name;
    <span class="hljs-meta">@Value</span>(<span class="hljs-string">&quot;20&quot;</span>)
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> age;
    <span class="hljs-meta">@Value</span>(<span class="hljs-string">&quot;2021/12/08&quot;</span>)
    <span class="hljs-keyword">private</span> Date birth;

    <span class="hljs-meta">@Autowired</span>  
    <span class="hljs-keyword">private</span> Teacher teacher;
    <span class="hljs-meta">@Resource</span> 
    <span class="hljs-keyword">private</span> ClassRoom classRoom;

}
</code></pre>
<p>&#x83B7;&#x53D6;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x503C;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Aoo</span> </span>{

    <span class="hljs-meta">@Value</span>(<span class="hljs-string">&quot;${test.boolean}&quot;</span>)
    <span class="hljs-keyword">private</span> Boolean testBoolean;

    <span class="hljs-meta">@Value</span>(<span class="hljs-string">&quot;${test.string}&quot;</span>)
    <span class="hljs-keyword">private</span> String testString;

    <span class="hljs-meta">@Value</span>(<span class="hljs-string">&quot;${test.integer}&quot;</span>)
    <span class="hljs-keyword">private</span> Integer testInteger;

    <span class="hljs-meta">@Value</span>(<span class="hljs-string">&quot;${test.long}&quot;</span>)
    <span class="hljs-keyword">private</span> Long testLong;

    <span class="hljs-meta">@Value</span>(<span class="hljs-string">&quot;${test.float}&quot;</span>)
    <span class="hljs-keyword">private</span> Float testFloat;

    <span class="hljs-meta">@Value</span>(<span class="hljs-string">&quot;${test.double}&quot;</span>)
    <span class="hljs-keyword">private</span> Double testDouble;

    <span class="hljs-meta">@Value</span>(<span class="hljs-string">&quot;#{&apos;${test.array}&apos;.split(&apos;,&apos;)}&quot;</span>)
    <span class="hljs-keyword">private</span> String[] testArray;

    <span class="hljs-meta">@Value</span>(<span class="hljs-string">&quot;#{&apos;${test.list}&apos;.split(&apos;,&apos;)}&quot;</span>)
    <span class="hljs-keyword">private</span> List&lt;String&gt; testList;

    <span class="hljs-meta">@Value</span>(<span class="hljs-string">&quot;#{&apos;${test.set}&apos;.split(&apos;,&apos;)}&quot;</span>)
    <span class="hljs-keyword">private</span> Set&lt;String&gt; testSet;

    <span class="hljs-meta">@Value</span>(<span class="hljs-string">&quot;#{${test.map}}&quot;</span>)
    <span class="hljs-keyword">private</span> Map&lt;String, Object&gt; testMap;

}
</code></pre>
<p>&#x914D;&#x7F6E;&#x6587;&#x4EF6; properties</p>
<pre><code class="lang-properties">test.boolean=true
test.string=abc
test.integer=123
test.long=123
test.float=1.2345678123456
test.double=1.2345678123456
test.array=1,3,4,5,6,1,2,3
test.list=1,3,4,5,6,1,2,3
test.set=1,3,4,5,6,1,2,3
test.map={name:&quot;zhangsan&quot;, age:18}
</code></pre>
<h2 id="spring&#x4E2D;&#x590D;&#x6742;&#x5BF9;&#x8C61;&#x7684;&#x521B;&#x5EFA;">spring&#x4E2D;&#x590D;&#x6742;&#x5BF9;&#x8C61;&#x7684;&#x521B;&#x5EFA;</h2>
<p>1.FactoryBean</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ConnectionFactoryBean</span>  <span class="hljs-keyword">implements</span> <span class="hljs-title">FactoryBean</span>&lt;<span class="hljs-title">Connection</span>&gt; </span>{

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> Connection <span class="hljs-title">getObject</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> Exception </span>{

        Class.forName(<span class="hljs-string">&quot;com.mysql.jdbc.Driver&quot;</span>);
        Connection connection = DriverManager.getConnection(<span class="hljs-string">&quot;jdbc:mysql:///java2215?serverTimezone=UTC&quot;</span>, <span class="hljs-string">&quot;root&quot;</span>, <span class="hljs-string">&quot;root&quot;</span>);
        <span class="hljs-keyword">return</span> connection;
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-keyword">public</span> Class&lt;?&gt; getObjectType() {
        <span class="hljs-keyword">return</span> Connection.class;
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">isSingleton</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">false</span>;
    }
}
</code></pre>
<p>xml&#x914D;&#x7F6E;&#x65B9;&#x5F0F;:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;conn&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;cn.kgc.spring.ioc.entity.ConnectionFactoryBean&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
</code></pre>
<p><img src="spring&#x6846;&#x67B6;.assets/image-20220628230959915.png" alt="image-20220628230959915"></p>
<p>2.&#x5B9E;&#x4F8B;&#x5DE5;&#x5382;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ConnectionFactoryBean</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> Connection <span class="hljs-title">getConnection</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> Exception </span>{
        Class.forName(<span class="hljs-string">&quot;com.mysql.jdbc.Driver&quot;</span>);
        Connection connection = DriverManager.getConnection(<span class="hljs-string">&quot;jdbc:mysql:///java2215?serverTimezone=UTC&amp;useSSL=false&quot;</span>, <span class="hljs-string">&quot;root&quot;</span>, <span class="hljs-string">&quot;root&quot;</span>);
        <span class="hljs-keyword">return</span> connection;
    }

}
</code></pre>
<p>xml&#x914D;&#x7F6E;&#x65B9;&#x5F0F;&#xFF1A;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;conn&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;cn.kgc.spring.ioc.entity.ConnectionFactoryBean&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;connection&quot;</span> <span class="hljs-attr">factory-bean</span>=<span class="hljs-string">&quot;conn&quot;</span> <span class="hljs-attr">factory-method</span>=<span class="hljs-string">&quot;getConnection&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
</code></pre>
<p><img src="spring&#x6846;&#x67B6;.assets/image-20220628231327604.png" alt="image-20220628231327604"></p>
<p>3.&#x9759;&#x6001;&#x5DE5;&#x5382;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ConnectionFactoryBean</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Connection <span class="hljs-title">getConnection</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> Exception </span>{
        Class.forName(<span class="hljs-string">&quot;com.mysql.jdbc.Driver&quot;</span>);
        Connection connection = DriverManager.getConnection(<span class="hljs-string">&quot;jdbc:mysql:///java2215?serverTimezone=UTC&amp;useSSL=false&quot;</span>, <span class="hljs-string">&quot;root&quot;</span>, <span class="hljs-string">&quot;root&quot;</span>);
        <span class="hljs-keyword">return</span> connection;
    }

}
</code></pre>
<p>xml&#x914D;&#x7F6E;&#x65B9;&#x5F0F;&#xFF1A;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;conn&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;cn.kgc.spring.ioc.entity.ConnectionFactoryBean&quot;</span> <span class="hljs-attr">factory-method</span>=<span class="hljs-string">&quot;getConnection&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
</code></pre>
<p><img src="spring&#x6846;&#x67B6;.assets/image-20220628231514244.png" alt="image-20220628231514244"></p>
<h2 id="spring&#x4E2D;bean&#x7684;&#x751F;&#x547D;&#x5468;&#x671F;">spring&#x4E2D;bean&#x7684;&#x751F;&#x547D;&#x5468;&#x671F;</h2>
<p>1.singleton  &#x5BB9;&#x5668;&#x542F;&#x52A8;&#x7684;&#x65F6;&#x5019;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#xFF0C;&#x5BB9;&#x5668;&#x6B63;&#x5E38;&#x5173;&#x95ED;&#x65F6;&#x9500;&#x6BC1;&#x5BF9;&#x8C61;</p>
<p>2.prototype  &#x83B7;&#x53D6;&#x5BF9;&#x8C61;&#x7684;&#x65F6;&#x5019;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#xFF0C;spring&#x5BB9;&#x5668;&#x4E0D;&#x8D1F;&#x8D23;&#x5BF9;&#x8C61;&#x7684;&#x9500;&#x6BC1;</p>
<p>&#x751F;&#x547D;&#x5468;&#x671F;&#x7684;&#x8FC7;&#x7A0B;&#xFF1A;</p>
<p>1.&#x8C03;&#x7528;&#x65E0;&#x53C2;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;</p>
<p>2.&#x8C03;&#x7528;set&#x65B9;&#x6CD5;&#x521D;&#x59CB;&#x5316;&#x5C5E;&#x6027;</p>
<p>3.&#x8C03;&#x7528;&#x521D;&#x59CB;&#x5316;&#x65B9;&#x6CD5;</p>
<p>4.&#x5BF9;&#x8C61;&#x521B;&#x5EFA;&#x5B8C;&#x6210;&#xFF0C;&#x4F7F;&#x7528;&#x5BF9;&#x8C61;</p>
<p>5.&#x5173;&#x95ED;&#x5BB9;&#x5668;&#xFF0C;&#x8C03;&#x7528;&#x9500;&#x6BC1;&#x7684;&#x65B9;&#x6CD5;</p>
<h2 id="spring-bean&#x4F5C;&#x7528;&#x57DF;">Spring Bean&#x4F5C;&#x7528;&#x57DF;</h2>
<p>&#x5728;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x9664;&#x4E86;&#x53EF;&#x4EE5;&#x5B9A;&#x4E49; Bean &#x7684;&#x5C5E;&#x6027;&#x503C;&#x548C;&#x76F8;&#x4E92;&#x4E4B;&#x95F4;&#x7684;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#xFF0C;&#x8FD8;&#x53EF;&#x4EE5;&#x58F0;&#x660E; Bean &#x7684;&#x4F5C;&#x7528;&#x57DF;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x5982;&#x679C;&#x6BCF;&#x6B21;&#x83B7;&#x53D6; Bean &#x65F6;&#xFF0C;&#x90FD;&#x9700;&#x8981;&#x4E00;&#x4E2A; Bean &#x5B9E;&#x4F8B;&#xFF0C;&#x90A3;&#x4E48;&#x5E94;&#x8BE5;&#x5C06; Bean &#x7684; scope &#x5C5E;&#x6027;&#x5B9A;&#x4E49;&#x4E3A; prototype&#xFF0C;&#x5982;&#x679C; Spring &#x9700;&#x8981;&#x6BCF;&#x6B21;&#x90FD;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x76F8;&#x540C;&#x7684; Bean &#x5B9E;&#x4F8B;&#xFF0C;&#x5219;&#x5E94;&#x5C06; Bean &#x7684; scope &#x5C5E;&#x6027;&#x5B9A;&#x4E49;&#x4E3A; singleton&#x3002;</p>
<p><strong>&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x79CD;&#x7C7B;</strong></p>
<p>Spring &#x5BB9;&#x5668;&#x5728;&#x521D;&#x59CB;&#x5316;&#x4E00;&#x4E2A; Bean &#x5B9E;&#x4F8B;&#x65F6;&#xFF0C;&#x540C;&#x65F6;&#x4F1A;&#x6307;&#x5B9A;&#x8BE5;&#x5B9E;&#x4F8B;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x3002;Spring 5 &#x652F;&#x6301;&#x4EE5;&#x4E0B; 6 &#x79CD;&#x4F5C;&#x7528;&#x57DF;&#x3002;</p>
<h4 id="1&#xFF09;singleton">1&#xFF09;singleton</h4>
<p>&#x9ED8;&#x8BA4;&#x503C;&#xFF0C;&#x5355;&#x4F8B;&#x6A21;&#x5F0F;&#xFF0C;&#x8868;&#x793A;&#x5728; Spring &#x5BB9;&#x5668;&#x4E2D;&#x53EA;&#x6709;&#x4E00;&#x4E2A; Bean &#x5B9E;&#x4F8B;&#xFF0C;Bean &#x4EE5;&#x5355;&#x4F8B;&#x7684;&#x65B9;&#x5F0F;&#x5B58;&#x5728;&#x3002;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;...&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;...&quot;</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">&quot;singleton&quot;</span>/&gt;</span>
</code></pre>
<h4 id="2&#xFF09;prototype">2&#xFF09;prototype</h4>
<p>&#x539F;&#x578B;&#x6A21;&#x5F0F;&#xFF0C;&#x8868;&#x793A;&#x6BCF;&#x6B21;&#x901A;&#x8FC7; Spring &#x5BB9;&#x5668;&#x83B7;&#x53D6; Bean &#x65F6;&#xFF0C;&#x5BB9;&#x5668;&#x90FD;&#x4F1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A; Bean &#x5B9E;&#x4F8B;&#x3002;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;...&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;...&quot;</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">&quot;prototype&quot;</span>/&gt;</span>
</code></pre>
<h4 id="3&#xFF09;request">3&#xFF09;request</h4>
<p>&#x6BCF;&#x6B21; HTTP &#x8BF7;&#x6C42;&#xFF0C;&#x5BB9;&#x5668;&#x90FD;&#x4F1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A; Bean &#x5B9E;&#x4F8B;&#x3002;&#x8BE5;&#x4F5C;&#x7528;&#x57DF;&#x53EA;&#x5728;&#x5F53;&#x524D; HTTP Request &#x5185;&#x6709;&#x6548;&#x3002;</p>
<h4 id="4&#xFF09;session">4&#xFF09;session</h4>
<p>&#x540C;&#x4E00;&#x4E2A; HTTP Session &#x5171;&#x4EAB;&#x4E00;&#x4E2A; Bean &#x5B9E;&#x4F8B;&#xFF0C;&#x4E0D;&#x540C;&#x7684; Session &#x4F7F;&#x7528;&#x4E0D;&#x540C;&#x7684; Bean &#x5B9E;&#x4F8B;&#x3002;&#x8BE5;&#x4F5C;&#x7528;&#x57DF;&#x4EC5;&#x5728;&#x5F53;&#x524D; HTTP Session &#x5185;&#x6709;&#x6548;&#x3002;</p>
<h4 id="5&#xFF09;application">5&#xFF09;application</h4>
<p>&#x540C;&#x4E00;&#x4E2A; Web &#x5E94;&#x7528;&#x5171;&#x4EAB;&#x4E00;&#x4E2A; Bean &#x5B9E;&#x4F8B;&#xFF0C;&#x8BE5;&#x4F5C;&#x7528;&#x57DF;&#x5728;&#x5F53;&#x524D; ServletContext &#x5185;&#x6709;&#x6548;&#x3002;</p>
<p>&#x7C7B;&#x4F3C;&#x4E8E; singleton&#xFF0C;&#x4E0D;&#x540C;&#x7684;&#x662F;&#xFF0C;singleton &#x8868;&#x793A;&#x6BCF;&#x4E2A; IoC &#x5BB9;&#x5668;&#x4E2D;&#x4EC5;&#x6709;&#x4E00;&#x4E2A; Bean &#x5B9E;&#x4F8B;&#xFF0C;&#x800C;&#x540C;&#x4E00;&#x4E2A; Web &#x5E94;&#x7528;&#x4E2D;&#x53EF;&#x80FD;&#x4F1A;&#x6709;&#x591A;&#x4E2A; IoC &#x5BB9;&#x5668;&#xFF0C;&#x4F46;&#x4E00;&#x4E2A; Web &#x5E94;&#x7528;&#x53EA;&#x4F1A;&#x6709;&#x4E00;&#x4E2A; ServletContext&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x8BF4; application &#x624D;&#x662F; Web &#x5E94;&#x7528;&#x4E2D;&#x8D27;&#x771F;&#x4EF7;&#x5B9E;&#x7684;&#x5355;&#x4F8B;&#x6A21;&#x5F0F;&#x3002;</p>
<h4 id="6&#xFF09;websocket">6&#xFF09;websocket</h4>
<p>websocket &#x7684;&#x4F5C;&#x7528;&#x57DF;&#x662F; WebSocket &#xFF0C;&#x5373;&#x5728;&#x6574;&#x4E2A; WebSocket &#x4E2D;&#x6709;&#x6548;</p>
<blockquote>
<p>spring&#x6CE8;&#x89E3;&#x5F00;&#x53D1;</p>
</blockquote>
<p>1.&#x5F00;&#x542F;&#x6CE8;&#x89E3;&#x7684;&#x5305;&#x626B;&#x63CF;</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!--&#x5F00;&#x542F;&#x6CE8;&#x89E3;&#x7684;&#x5305;&#x626B;&#x63CF;--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">context:component-scan</span> <span class="hljs-attr">base-package</span>=<span class="hljs-string">&quot;cn.kgc.spring&quot;</span>/&gt;</span>
</code></pre>
<p>2.&#x5E38;&#x7528;&#x7684;&#x6CE8;&#x89E3;</p>
<pre><code>@Repository  dao&#x5C42;
@Component   &#x7EC4;&#x4EF6;&#x901A;&#x7528;
@Service     service&#x5C42;
@Controller  &#x63A7;&#x5236;&#x5C42;
</code></pre><p>&#x56DB;&#x4E2A;&#x6CE8;&#x89E3;&#x7684;&#x529F;&#x80FD;&#x662F;&#x4E00;&#x6837;&#x7684;&#xFF0C;&#x53EA;&#x662F;&#x4F7F;&#x7528;&#x4E0D;&#x540C;&#x7684;&#x6CE8;&#x89E3;&#x53EF;&#x4EE5;&#x770B;&#x51FA;&#x5C42;&#x6B21;&#x7ED3;&#x6784;</p>
<p><strong>3.&#x4F5C;&#x7528;&#x57DF;&#x6CE8;&#x89E3;</strong></p>
<pre><code class="lang-java"><span class="hljs-meta">@scope</span>(<span class="hljs-string">&quot;singleton&quot;</span>)
<span class="hljs-meta">@scope</span>(<span class="hljs-string">&quot;prototype&quot;</span>)
</code></pre>
<h2 id="spring&#x6846;&#x67B6;&#x4E2D;aop">Spring&#x6846;&#x67B6;&#x4E2D;AOP</h2>
<p><strong>1.&#x4EE3;&#x7406;&#x6A21;&#x5F0F;&#x8BB2;&#x89E3;</strong></p>
<p><img src="spring&#x6846;&#x67B6;.assets/image-20210815205906907.png" alt="image-20210815205906907"></p>
<p><strong>&#x4F5C;&#x7528;&#xFF1A;</strong></p>
<p>&#x901A;&#x8FC7;&#x4EE3;&#x7406;&#x7C7B;&#x4E3A;&#x539F;&#x59CB;&#x7C7B;&#x589E;&#x52A0;&#x989D;&#x5916;&#x7684;&#x529F;&#x80FD;</p>
<p><strong>&#x4EE3;&#x7406;&#x5206;&#x7C7B;&#xFF1A;</strong></p>
<p><strong>1.1&#x9759;&#x6001;&#x4EE3;&#x7406;</strong></p>
<p><strong>&#x9759;&#x6001;&#x4EE3;&#x7406;&#x4F18;&#x7F3A;&#x70B9;</strong></p>
<p>1&#xFF09;&#x4F18;&#x70B9; &#xFF1A;&#x5728;&#x4E0D;&#x4FEE;&#x6539;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x7684;&#x529F;&#x80FD;&#x524D;&#x63D0;&#x4E0B;&#xFF0C;&#x80FD;&#x901A;&#x8FC7;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x5BF9;&#x76EE;&#x6807;&#x529F;&#x80FD;&#x6269;&#x5C55;
2&#xFF09;&#x7F3A;&#x70B9; &#xFF1A;&#x56E0;&#x4E3A;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x9700;&#x8981;&#x4E0E;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x5B9E;&#x73B0;&#x4E00;&#x6837;&#x7684;&#x63A5;&#x53E3;&#xFF0C;&#x6240;&#x4EE5;&#x4F1A;&#x5F88;&#x591A;&#x4EE3;&#x7406;&#x7C7B; ,&#x4E00;&#x65E6;&#x63A5;&#x53E3;&#x589E;&#x52A0;&#x65B9;&#x6CD5;&#xFF0C;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x4E0E;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x90FD;&#x8981;&#x7EF4;&#x62A4;</p>
<p><strong>&#x5F00;&#x53D1;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x5219;&#xFF1A;</strong></p>
<p>1.&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x548C;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x5B9E;&#x73B0;&#x76F8;&#x540C;&#x7684;&#x63A5;&#x53E3;</p>
<p>2.&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x4F9D;&#x8D56;&#x4E8E;&#x76EE;&#x6807;&#x5BF9;&#x8C61;</p>
<p><strong>1.2&#x52A8;&#x6001;&#x4EE3;&#x7406;&#xFF08;&#x53CD;&#x5C04;&#xFF09;</strong></p>
<p>&#x7A0B;&#x5E8F;&#x8FD0;&#x884C;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x901A;&#x8FC7;jdk&#x63D0;&#x4F9B;&#x4EE3;&#x7406;&#x6280;&#x672F;&#x52A8;&#x6001;&#x7684;&#x4E3A;&#x67D0;&#x4E2A;&#x7C7B;&#x4EA7;&#x751F;&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x7684;&#x8FC7;&#x7A0B;</p>
<p><strong>&#x5F00;&#x53D1;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x5219;&#xFF1A;</strong></p>
<p>1&#xFF09;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#xFF0C;&#x4F46;&#x662F;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x8981;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#xFF0C;&#x5426;&#x5219;&#x4E0D;&#x80FD;&#x7528;JDK&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x3002;
2&#xFF09;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x7684;&#x751F;&#x6210;&#xFF0C;&#x662F;&#x5229;&#x7528;JDK&#x7684;API&#xFF0C;&#x52A8;&#x6001;&#x7684;&#x5728;&#x5185;&#x5B58;&#x4E2D;&#x6784;&#x5EFA;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x3002;
3&#xFF09;&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x4E5F;&#x53EB;&#x505A; &#xFF1A;JDK&#x4EE3;&#x7406;&#x3001;&#x63A5;&#x53E3;&#x4EE3;&#x7406;</p>
<pre><code class="lang-java"> <span class="hljs-meta">@Test</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">test4</span><span class="hljs-params">()</span> </span>{ <span class="hljs-comment">//jdk&#x7684;&#x52A8;&#x6001;&#x4EE3;&#x7406;</span>

        <span class="hljs-comment">// &#x88AB;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;</span>
        UserServiceImpl userService = <span class="hljs-keyword">new</span> UserServiceImpl();
        InvocationHandler handler = <span class="hljs-keyword">new</span> InvocationHandler() {
            <span class="hljs-comment">/**
             * <span class="hljs-doctag">@param</span> proxy  &#x751F;&#x6210;&#x7684;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;  &#x53EF;&#x5FFD;&#x7565;
             * <span class="hljs-doctag">@param</span> method  &#x539F;&#x59CB;&#x5BF9;&#x8C61;&#x4E2D;&#x7684;&#x65B9;&#x6CD5;
             * <span class="hljs-doctag">@param</span> args     &#x539F;&#x59CB;&#x5BF9;&#x8C61;&#x4E2D;&#x7684;&#x53C2;&#x6570;
             * <span class="hljs-doctag">@return</span>
             * <span class="hljs-doctag">@throws</span> Throwable
             */</span>
            <span class="hljs-meta">@Override</span>
            <span class="hljs-function"><span class="hljs-keyword">public</span> Object <span class="hljs-title">invoke</span><span class="hljs-params">(Object proxy, Method method, Object[] args)</span> <span class="hljs-keyword">throws</span> Throwable </span>{
                System.out.println(<span class="hljs-string">&quot;------log---------&quot;</span>);
                Object invoke = method.invoke(userService, args);
                <span class="hljs-keyword">return</span> invoke;
            }
        };

        <span class="hljs-comment">/**
         *&#x53C2;&#x6570;1&#xFF1A;&#x7C7B;&#x52A0;&#x8F7D;&#x5668;&#xFF0C;&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x6CA1;&#x6709;&#x7C7B;&#x52A0;&#x8F7D;&#x5668; &#x9700;&#x8981;&#x501F;&#x52A9;&#x522B;&#x7684;&#x7C7B;&#x7684;&#x52A0;&#x8F7D;&#x5668;&#x5B9E;&#x73B0;&#x7C7B;&#x7684;&#x52A0;&#x8F7D;
         * &#x7C7B;&#x52A0;&#x8F7D;&#x5668;&#x7684;&#x4F5C;&#x7528;&#xFF1A;
         *  1.&#x52A0;&#x8F7D;class&#x6587;&#x4EF6;&#x5230;JVM&#x865A;&#x62DF;&#x673A;
         *  2.&#x521B;&#x5EFA;&#x7C7B;&#x7684;class&#x5BF9;&#x8C61;&#xFF0C;&#x8FDB;&#x800C;&#x521B;&#x5EFA;&#x7C7B;&#x7684;&#x5B9E;&#x4F8B;&#x5316;&#x5BF9;&#x8C61;
         *
         * &#x53C2;&#x6570;2:&#x539F;&#x59CB;&#x7C7B;&#x5B9E;&#x73B0;&#x7684;&#x6240;&#x6709;&#x63A5;&#x53E3;  &#x57FA;&#x4E8E;jdk&#x7684;&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x8981;&#x6C42;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x548C;&#x539F;&#x59CB;&#x5BF9;&#x8C61;&#x8981;&#x5B9E;&#x73B0;&#x76F8;&#x540C;&#x7684;&#x63A5;&#x53E3;
         *
         * &#x53C2;&#x6570;3&#xFF1A;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x989D;&#x5916;&#x589E;&#x52A0;&#x7684;&#x529F;&#x80FD;  InvocationHandler
         *
         */</span>
  UserService o =(UserService) Proxy.newProxyInstance(TestStaticProxy.class.getClassLoader(), userService.getClass().getInterfaces(), handler);
        o.login();
        o.register();

    }
</code></pre>
<p><strong>&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#xFF1A;</strong></p>
<p><img src="spring&#x6846;&#x67B6;.assets/image-20220630211228933.png" alt="image-20220630211228933"></p>
<p><strong>&#x57FA;&#x4E8E;CGLib&#x7684;&#x52A8;&#x6001;&#x4EE3;&#x7406;</strong></p>
<p><strong>&#x5F00;&#x53D1;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x7684;&#x539F;&#x5219;&#xFF1A;</strong></p>
<p>1.&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x65E0;&#x9700;&#x548C;&#x539F;&#x59CB;&#x7C7B;&#x5BF9;&#x8C61;&#x5B9E;&#x73B0;&#x76F8;&#x540C;&#x7684;&#x63A5;&#x53E3;</p>
<p>2.&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#x548C;&#x539F;&#x59CB;&#x7C7B;&#x5BF9;&#x8C61;&#x8981;&#x5B58;&#x5728;&#x7236;&#x5B50;&#x7C7B;&#x5173;&#x7CFB;</p>
<p><strong>&#x5B9E;&#x73B0;&#x6B65;&#x9AA4;</strong></p>
<pre><code class="lang-java"><span class="hljs-meta">@Test</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">test5</span><span class="hljs-params">()</span></span>{ <span class="hljs-comment">//&#x57FA;&#x4E8E;cglib&#x7684;&#x52A8;&#x6001;&#x4EE3;&#x7406;</span>

        UserServiceImpl userService = <span class="hljs-keyword">new</span> UserServiceImpl();

        Enhancer enhancer = <span class="hljs-keyword">new</span> Enhancer();
        enhancer.setClassLoader(<span class="hljs-keyword">this</span>.getClass().getClassLoader());
        enhancer.setSuperclass(userService.getClass());
        <span class="hljs-comment">//&#x8BBE;&#x7F6E;&#x989D;&#x5916;&#x7684;&#x529F;&#x80FD;</span>
        MethodInterceptor callback = <span class="hljs-keyword">new</span> MethodInterceptor() {
            <span class="hljs-comment">//&#x7B49;&#x4EF7;&#x4E8E;  jdk&#x4EE3;&#x7406;&#x4E2D; invocationHandler &#x4E2D;&#x7684; invoke &#x65B9;&#x6CD5;</span>
            <span class="hljs-comment">/**
             * <span class="hljs-doctag">@param</span> o          &#x4EE3;&#x7406;&#x5BF9;&#x8C61;
             * <span class="hljs-doctag">@param</span> method    &#x539F;&#x59CB;&#x5BF9;&#x8C61;&#x4E2D;&#x7684;&#x65B9;&#x6CD5;
             * <span class="hljs-doctag">@param</span> objects   &#x539F;&#x59CB;&#x5BF9;&#x8C61;&#x4E2D;&#x7684;&#x53C2;&#x6570;
             * <span class="hljs-doctag">@param</span> methodProxy  &#x4EE3;&#x7406;&#x65B9;&#x6CD5;
             * <span class="hljs-doctag">@return</span>    &#x539F;&#x59CB;&#x65B9;&#x6CD5;&#x7684;&#x8FD4;&#x56DE;&#x503C;
             * <span class="hljs-doctag">@throws</span> Throwable
             */</span>
            <span class="hljs-meta">@Override</span>
            <span class="hljs-function"><span class="hljs-keyword">public</span> Object <span class="hljs-title">intercept</span><span class="hljs-params">(Object o, Method method, Object[] objects, MethodProxy methodProxy)</span> <span class="hljs-keyword">throws</span> Throwable </span>{
                System.out.println(<span class="hljs-string">&quot;---------cglib log------------&quot;</span>);
                <span class="hljs-keyword">return</span>  method.invoke(userService, objects);
            }
        };
        enhancer.setCallback(callback);

        <span class="hljs-comment">// &#x521B;&#x5EFA;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;</span>
        UserService usrService =(UserService) enhancer.create();
        usrService.login();
        usrService.register();
    }
</code></pre>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;</p>
<p><img src="spring&#x6846;&#x67B6;.assets/image-20220630210959626.png" alt="image-20220630210959626"></p>
<p><strong>2.AOP&#x6982;&#x8FF0;</strong></p>
<p>AOP&#x4E3A;Aspect Oriented Programming&#x7684;&#x7F29;&#x5199;&#xFF0C;&#x662F;&#x9762;&#x5411;&#x5207;&#x9762;&#x7F16;&#x7A0B;&#xFF0C;&#x901A;&#x8FC7;&#x9884;&#x7F16;&#x8BD1;&#x65B9;&#x5F0F;&#x548C;&#x8FD0;&#x884C;&#x671F;&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x5B9E;&#x73B0;&#x7A0B;&#x5E8F;&#x529F;&#x80FD;&#x7684;&#x7EDF;&#x4E00;&#x7EF4;&#x62A4;&#x7684;&#x4E00;&#x79CD;&#x6280;&#x672F;&#x3002;AOP&#x662F;OOP&#x7684;&#x5EF6;&#x7EED;&#xFF0C;&#x662F;&#x8F6F;&#x4EF6;&#x5F00;&#x53D1;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x70ED;&#x70B9;&#xFF0C;&#x4E5F;&#x662F;Spring&#x6846;&#x67B6;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x91CD;&#x8981;&#x5185;&#x5BB9;&#xFF0C;&#x662F;&#x51FD;&#x6570;&#x5F0F;&#x7F16;&#x7A0B;&#x7684;&#x4E00;&#x79CD;&#x884D;&#x751F;&#x8303;&#x578B;</p>
<p>AOP&#x53EF;&#x4EE5;&#x5206;&#x79BB;&#x4E1A;&#x52A1;&#x4EE3;&#x7801;&#x548C;&#x5173;&#x6CE8;&#x70B9;&#x4EE3;&#x7801;&#xFF08;&#x91CD;&#x590D;&#x4EE3;&#x7801;&#xFF09;&#xFF0C;&#x5728;&#x6267;&#x884C;&#x4E1A;&#x52A1;&#x4EE3;&#x7801;&#x65F6;&#xFF0C;&#x52A8;&#x6001;&#x7684;&#x6CE8;&#x5165;&#x5173;&#x6CE8;&#x70B9;&#x4EE3;&#x7801;&#x3002;&#x5207;&#x9762;&#x5C31;&#x662F;&#x5173;&#x6CE8;&#x70B9;&#x4EE3;&#x7801;&#x5F62;&#x6210;&#x7684;&#x7C7B;&#x3002;Spring AOP&#x4E2D;&#x7684;&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x4E3B;&#x8981;&#x6709;&#x4E24;&#x79CD;&#x65B9;&#x5F0F;&#xFF0C;JDK&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x548C;CGLIB&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x3002;JDK&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x901A;&#x8FC7;&#x53CD;&#x5C04;&#x6765;&#x63A5;&#x6536;&#x88AB;&#x4EE3;&#x7406;&#x7684;&#x7C7B;&#xFF0C;&#x5E76;&#x4E14;&#x8981;&#x6C42;&#x88AB;&#x4EE3;&#x7406;&#x7684;&#x7C7B;&#x5FC5;&#x987B;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;</p>
<p><img src="spring&#x6846;&#x67B6;.assets/image-20210815223318375.png" alt="image-20210815223318375"></p>
<h2 id="aop-&#x5B9E;&#x73B0;&#x5206;&#x7C7B;">AOP &#x5B9E;&#x73B0;&#x5206;&#x7C7B;</h2>
<p>AOP &#x8981;&#x8FBE;&#x5230;&#x7684;&#x6548;&#x679C;&#x662F;&#xFF0C;&#x4FDD;&#x8BC1;&#x5F00;&#x53D1;&#x8005;&#x4E0D;&#x4FEE;&#x6539;&#x6E90;&#x4EE3;&#x7801;&#x7684;&#x524D;&#x63D0;&#x4E0B;&#xFF0C;&#x53BB;&#x4E3A;&#x7CFB;&#x7EDF;&#x4E2D;&#x7684;&#x4E1A;&#x52A1;&#x7EC4;&#x4EF6;&#x6DFB;&#x52A0;&#x67D0;&#x79CD;&#x901A;&#x7528;&#x529F;&#x80FD;&#xFF0C;&#x6309;&#x7167; AOP &#x6846;&#x67B6;&#x4FEE;&#x6539;&#x6E90;&#x4EE3;&#x7801;&#x7684;&#x65F6;&#x673A;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x5176;&#x5206;&#x4E3A;&#x4E24;&#x7C7B;&#xFF1A;</p>
<ul>
<li>&#x9759;&#x6001; AOP &#x5B9E;&#x73B0;&#xFF0C; AOP &#x6846;&#x67B6;&#x5728;&#x7F16;&#x8BD1;&#x9636;&#x6BB5;&#x5BF9;&#x7A0B;&#x5E8F;&#x6E90;&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x4FEE;&#x6539;&#xFF0C;&#x751F;&#x6210;&#x4E86;&#x9759;&#x6001;&#x7684; AOP &#x4EE3;&#x7406;&#x7C7B;&#xFF08;&#x751F;&#x6210;&#x7684; *.class &#x6587;&#x4EF6;&#x5DF2;&#x7ECF;&#x88AB;&#x6539;&#x6389;&#x4E86;&#xFF0C;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x7279;&#x5B9A;&#x7684;&#x7F16;&#x8BD1;&#x5668;&#xFF09;&#xFF0C;&#x6BD4;&#x5982; AspectJ&#x3002;</li>
<li>&#x52A8;&#x6001; AOP &#x5B9E;&#x73B0;&#xFF0C; AOP &#x6846;&#x67B6;&#x5728;&#x8FD0;&#x884C;&#x9636;&#x6BB5;&#x5BF9;&#x52A8;&#x6001;&#x751F;&#x6210;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#xFF08;&#x5728;&#x5185;&#x5B58;&#x4E2D;&#x4EE5; JDK &#x52A8;&#x6001;&#x4EE3;&#x7406;&#xFF0C;&#x6216; CGlib &#x52A8;&#x6001;&#x5730;&#x751F;&#x6210; AOP &#x4EE3;&#x7406;&#x7C7B;&#xFF09;&#xFF0C;&#x5982; SpringAOP</li>
</ul>
<h2 id="aop-&#x672F;&#x8BED;">AOP &#x672F;&#x8BED;</h2>
<ul>
<li><p>&#x6A2A;&#x5207;&#x5173;&#x6CE8;&#x70B9;:&#x8DE8;&#x8D8A;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x591A;&#x4E2A;&#x6A21;&#x5757;&#x7684;&#x65B9;&#x6CD5;&#x6216;&#x529F;&#x80FD;&#x3002;&#x5373;&#x662F;&#xFF0C;&#x4E0E;&#x6211;&#x4EEC;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x65E0;&#x5173;&#x7684;&#xFF0C;&#x4F46;&#x662F;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5173;&#x6CE8;&#x7684;&#x90E8;&#x5206;&#xFF0C;&#x5C31;&#x662F;&#x6A2A;&#x5207;&#x5173;&#x6CE8;&#x70B9;&#x3002;&#x5982;&#x65E5;&#x5FD7;,&#x5B89;&#x5168;,&#x7F13;&#x5B58;,&#x4E8B;&#x52A1;&#x7B49;&#x7B49;....</p>
</li>
<li><p>&#x5207;&#x9762;(ASPECT) :&#x6A2A;&#x5207;&#x5173;&#x6CE8;&#x70B9;&#x88AB;&#x6A21;&#x5757;&#x5316;&#x7684;&#x7279;&#x6B8A;&#x5BF9;&#x8C61;&#x3002;&#x5373;&#xFF0C;&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x7C7B;</p>
</li>
<li><p>&#x901A;&#x77E5;(Advice) :&#x5207;&#x9762;&#x5FC5;&#x987B;&#x8981;&#x5B8C;&#x6210;&#x7684;&#x5DE5;&#x4F5C;&#x3002;&#x5373;&#xFF0C;&#x5B83;&#x662F;&#x7C7B;&#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;</p>
<p>&#x524D;&#x7F6E;&#x901A;&#x77E5;   &#x540E;&#x7F6E;&#x901A;&#x77E5; &#x73AF;&#x7ED5;&#x901A;&#x77E5;   &#x5F02;&#x5E38;&#x901A;&#x77E5;   &#x6700;&#x7EC8;&#x901A;&#x77E5;</p>
</li>
<li><p>&#x76EE;&#x6807;(Target) ;&#x88AB;&#x901A;&#x77E5;&#x5BF9;&#x8C61;</p>
</li>
<li><p>&#x4EE3;&#x7406;(Proxy) :&#x5411;&#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x5E94;&#x7528;&#x901A;&#x77E5;&#x4E4B;&#x540E;&#x521B;&#x5EFA;&#x7684;&#x5BF9;&#x8C61;</p>
</li>
<li><p>&#x5207;&#x5165;&#x70B9;(PointCut) :&#x5207;&#x9762;&#x901A;&#x77E5;&#x6267;&#x884C;&#x7684;&#x201C;&#x5730;&#x70B9;&quot;&#x7684;&#x5B9A;&#x4E49;</p>
</li>
<li><p>&#x8FDE;&#x63A5;&#x70B9;JointPoint) :&#x4E0E;&#x5207;&#x5165;&#x70B9;&#x5339;&#x914D;&#x7684;&#x6267;&#x884C;&#x70B9;</p>
</li>
</ul>
<p><strong>&#x5FEB;&#x901F;&#x4F7F;&#x7528;</strong></p>
<p>1.&#x57FA;&#x4E8E;&#x63A5;&#x53E3;&#x5F62;&#x5F0F;&#x5B9E;&#x73B0;</p>
<p>&#x4F7F;&#x7528;Spring aop&#x63A5;&#x53E3;&#x65B9;&#x5F0F;&#x5B9E;&#x73B0;aop, &#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x81EA;&#x5B9A;&#x4E49;&#x901A;&#x77E5;&#x6765;&#x4F9B;Spring AOP&#x8BC6;&#x522B;&#x5BF9;&#x5E94;&#x5B9E;&#x73B0;&#x7684;&#x63A5;&#x53E3;&#x662F;:</p>
<ol>
<li>&#x524D;&#x7F6E;&#x901A;&#x77E5;: MethodBeforeAdvice</li>
<li>&#x8FD4;&#x56DE;&#x901A;&#x77E5;:AfterReturningAdvice</li>
<li>&#x5F02;&#x5E38;&#x901A;&#x77E5;:ThrowsAdvice</li>
<li>&#x73AF;&#x7ED5;&#x901A;&#x77E5;:MethodInterceptor</li>
</ol>
<p><strong>&#x901A;&#x77E5;&#x7684;&#x7C7B;&#x578B;</strong></p>
<p>Spring &#x65B9;&#x9762;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x4E0B;&#x9762;&#x63D0;&#x5230;&#x7684;&#x4E94;&#x79CD;&#x901A;&#x77E5;&#x5DE5;&#x4F5C;&#xFF1A;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x901A;&#x77E5;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">&#x524D;&#x7F6E;&#x901A;&#x77E5;</td>
<td style="text-align:left">&#x5728;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x6267;&#x884C;&#x4E4B;&#x524D;&#xFF0C;&#x6267;&#x884C;&#x901A;&#x77E5;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">&#x540E;&#x7F6E;&#x901A;&#x77E5;</td>
<td style="text-align:left">&#x5728;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x6267;&#x884C;&#x4E4B;&#x540E;&#xFF0C;&#x4E0D;&#x8003;&#x8651;&#x5176;&#x7ED3;&#x679C;&#xFF0C;&#x6267;&#x884C;&#x901A;&#x77E5;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">&#x8FD4;&#x56DE;&#x540E;&#x901A;&#x77E5;</td>
<td style="text-align:left">&#x5728;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x6267;&#x884C;&#x4E4B;&#x540E;&#xFF0C;&#x53EA;&#x6709;&#x5728;&#x65B9;&#x6CD5;&#x6210;&#x529F;&#x5B8C;&#x6210;&#x65F6;&#xFF0C;&#x624D;&#x80FD;&#x6267;&#x884C;&#x901A;&#x77E5;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">&#x629B;&#x51FA;&#x5F02;&#x5E38;&#x540E;&#x901A;&#x77E5;</td>
<td style="text-align:left">&#x5728;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x6267;&#x884C;&#x4E4B;&#x540E;&#xFF0C;&#x53EA;&#x6709;&#x5728;&#x65B9;&#x6CD5;&#x9000;&#x51FA;&#x629B;&#x51FA;&#x5F02;&#x5E38;&#x65F6;&#xFF0C;&#x624D;&#x80FD;&#x6267;&#x884C;&#x901A;&#x77E5;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">&#x73AF;&#x7ED5;&#x901A;&#x77E5;</td>
<td style="text-align:left">&#x5728;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x8C03;&#x7528;&#x4E4B;&#x524D;&#x548C;&#x4E4B;&#x540E;&#xFF0C;&#x6267;&#x884C;&#x901A;&#x77E5;&#x3002;</td>
</tr>
</tbody>
</table>
<p><strong>&#x6848;&#x4F8B;</strong></p>
<p>&#x4E1A;&#x52A1;&#x63A5;&#x53E3;</p>
<pre><code class="lang-java"><span class="hljs-comment">/**
 * &#x4F7F;&#x7528;&#x63A5;&#x53E3;&#x65B9;&#x5F0F;&#x5B9E;&#x73B0;AOP, &#x9ED8;&#x8BA4;&#x901A;&#x8FC7;JDK&#x7684;&#x52A8;&#x6001;&#x4EE3;&#x7406;&#x6765;&#x5B9E;&#x73B0;. &#x975E;&#x63A5;&#x53E3;&#x65B9;&#x5F0F;, &#x4F7F;&#x7528;&#x7684;&#x662F;cglib&#x5B9E;&#x73B0;&#x52A8;&#x6001;&#x4EE3;&#x7406;
 */</span>

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">IBaseCalculate</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">add</span><span class="hljs-params">(<span class="hljs-keyword">int</span> numA, <span class="hljs-keyword">int</span> numB)</span></span>;

    <span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">sub</span><span class="hljs-params">(<span class="hljs-keyword">int</span> numA, <span class="hljs-keyword">int</span> numB)</span></span>;

    <span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">div</span><span class="hljs-params">(<span class="hljs-keyword">int</span> numA, <span class="hljs-keyword">int</span> numB)</span></span>;

    <span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">multi</span><span class="hljs-params">(<span class="hljs-keyword">int</span> numA, <span class="hljs-keyword">int</span> numB)</span></span>;

}
</code></pre>
<p>&#x5B9E;&#x73B0;&#x7C7B;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">BaseCalculate</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">IBaseCalculate</span> </span>{

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">add</span><span class="hljs-params">(<span class="hljs-keyword">int</span> numA, <span class="hljs-keyword">int</span> numB)</span> </span>{
        System.out.println(<span class="hljs-string">&quot;&#x6267;&#x884C;&#x76EE;&#x6807;&#x65B9;&#x6CD5;: add&quot;</span>);
        <span class="hljs-keyword">return</span> numA + numB;
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">sub</span><span class="hljs-params">(<span class="hljs-keyword">int</span> numA, <span class="hljs-keyword">int</span> numB)</span> </span>{
        System.out.println(<span class="hljs-string">&quot;&#x6267;&#x884C;&#x76EE;&#x6807;&#x65B9;&#x6CD5;: sub&quot;</span>);
        <span class="hljs-keyword">return</span> numA - numB;
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">multi</span><span class="hljs-params">(<span class="hljs-keyword">int</span> numA, <span class="hljs-keyword">int</span> numB)</span> </span>{
        System.out.println(<span class="hljs-string">&quot;&#x6267;&#x884C;&#x76EE;&#x6807;&#x65B9;&#x6CD5;: multi&quot;</span>);
        <span class="hljs-keyword">return</span> numA * numB;
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">div</span><span class="hljs-params">(<span class="hljs-keyword">int</span> numA, <span class="hljs-keyword">int</span> numB)</span> </span>{
        System.out.println(<span class="hljs-string">&quot;&#x6267;&#x884C;&#x76EE;&#x6807;&#x65B9;&#x6CD5;: div&quot;</span>);
        <span class="hljs-keyword">return</span> numA / numB;
    }
}
</code></pre>
<p><strong>&#x901A;&#x77E5;&#x7C7B;</strong></p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">BaseAdvice</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">MethodBeforeAdvice</span> ,<span class="hljs-title">AfterReturningAdvice</span>,<span class="hljs-title">ThrowsAdvice</span>&#xFF0C;<span class="hljs-title">MethodInterceptor</span></span>{
    <span class="hljs-comment">/**
     *
     * <span class="hljs-doctag">@param</span> method &#x5207;&#x5165;&#x7684;&#x65B9;&#x6CD5;
     * <span class="hljs-doctag">@param</span> args &#x5207;&#x5165;&#x65B9;&#x6CD5;&#x7684;&#x53C2;&#x6570;
     * <span class="hljs-doctag">@param</span> target &#x76EE;&#x6807;&#x5BF9;&#x8C61;
     * <span class="hljs-doctag">@throws</span> Throwable
     */</span>
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">before</span><span class="hljs-params">(Method method, Object[] args, Object target)</span> <span class="hljs-keyword">throws</span> Throwable </span>{
        System.out.println(<span class="hljs-string">&quot;===========&#x8FDB;&#x5165;beforeAdvice()============&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;&#x76EE;&#x6807;&#x5BF9;&#x8C61;:&quot;</span> + target);
        System.out.println(<span class="hljs-string">&quot;&#x65B9;&#x6CD5;&#x540D;: &quot;</span>+method);
        System.out.println(<span class="hljs-string">&quot;&#x5373;&#x5C06;&#x8FDB;&#x5165;&#x5207;&#x5165;&#x70B9;&#x65B9;&#x6CD5;&quot;</span>);
    }

    <span class="hljs-comment">/**
     *
     * <span class="hljs-doctag">@param</span> returnValue &#x5207;&#x5165;&#x70B9;&#x6267;&#x884C;&#x5B8C;&#x65B9;&#x6CD5;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x4F46;&#x4E0D;&#x80FD;&#x4FEE;&#x6539;
     * <span class="hljs-doctag">@param</span> method &#x5207;&#x5165;&#x70B9;&#x65B9;&#x6CD5;
     * <span class="hljs-doctag">@param</span> args &#x5207;&#x5165;&#x70B9;&#x65B9;&#x6CD5;&#x7684;&#x53C2;&#x6570;&#x6570;&#x7EC4;
     * <span class="hljs-doctag">@param</span> target &#x76EE;&#x6807;&#x5BF9;&#x8C61;
     * <span class="hljs-doctag">@throws</span> Throwable
     */</span>
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">afterReturning</span><span class="hljs-params">(Object returnValue, Method method, Object[] args, Object target)</span> <span class="hljs-keyword">throws</span> Throwable </span>{
        System.out.println(<span class="hljs-string">&quot;==========&#x8FDB;&#x5165;afterReturning()=========== \n&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;&#x5207;&#x5165;&#x70B9;&#x65B9;&#x6CD5;&#x6267;&#x884C;&#x5B8C;&#x6210;&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;&#x540E;&#x7F6E;&#x901A;&#x77E5;--&#x76EE;&#x6807;&#x5BF9;&#x8C61;:&quot;</span> + target);
        System.out.println(<span class="hljs-string">&quot;&#x540E;&#x7F6E;&#x901A;&#x77E5;--&#x65B9;&#x6CD5;&#x540D;: &quot;</span>+method);
        System.out.println(<span class="hljs-string">&quot;&#x540E;&#x7F6E;&#x901A;&#x77E5;--&#x65B9;&#x6CD5;&#x5165;&#x53C2;: &quot;</span>+ args.toString());
        System.out.println(<span class="hljs-string">&quot;&#x540E;&#x7F6E;&#x901A;&#x77E5;--&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x503C;: &quot;</span>+ returnValue);
    }

    <span class="hljs-comment">/**
        &#x5F02;&#x5E38;&#x901A;&#x77E5;   &#x63A5;&#x53E3;&#x4E2D;&#x6CA1;&#x6709;&#x62BD;&#x8C61;&#x65B9;&#x6CD5; &#x5229;&#x7528;&#x53CD;&#x5C04;&#x5B9E;&#x73B0; 
    */</span>

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">afterThrowing</span><span class="hljs-params">(Exception e)</span></span>{
        System.out.println(<span class="hljs-string">&quot;&#x5F02;&#x5E38;&#x4E3A;:&quot;</span>+e.getMessage());
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> Object <span class="hljs-title">invoke</span><span class="hljs-params">(MethodInvocation methodInvocation)</span> <span class="hljs-keyword">throws</span> Throwable </span>{
       System.out.println(<span class="hljs-string">&quot;=================&#x73AF;&#x7ED5;&#x901A;&#x77E5;&#x5F00;&#x59CB;===================&quot;</span>);
        String method = methodInvocation.getMethod().getName();
        System.out.println(<span class="hljs-string">&quot;&#x65B9;&#x6CD5;&#x540D;:&quot;</span>+method);
        Object[] arguments = methodInvocation.getArguments();
        System.out.println(<span class="hljs-string">&quot;&#x65B9;&#x6CD5;&#x53C2;&#x6570;:&quot;</span>+Arrays.toString(arguments));
        Object aThis = methodInvocation.getThis();
        System.out.println(<span class="hljs-string">&quot;&#x76EE;&#x6807;&#x5BF9;&#x8C61;:&quot;</span>+aThis);
        System.out.println(<span class="hljs-string">&quot;=================&#x524D;&#x7F6E;&#x901A;&#x77E5;===================&quot;</span>);
        <span class="hljs-comment">//&#x6267;&#x884C;&#x76EE;&#x6807;&#x65B9;&#x6CD5;</span>
        Object proceed = methodInvocation.proceed();
        System.out.println(<span class="hljs-string">&quot;=================&#x540E;&#x7F6E;&#x901A;&#x77E5;===================&quot;</span>);
        System.out.println(<span class="hljs-string">&quot;&#x8FD4;&#x56DE;&#x503C;:&quot;</span>+proceed);
        System.out.println(<span class="hljs-string">&quot;=================&#x73AF;&#x7ED5;&#x901A;&#x77E5;&#x7ED3;&#x675F;===================&quot;</span>);
        <span class="hljs-keyword">return</span> proceed;
    }

}
</code></pre>
<p><strong>&#x57FA;&#x4E8E;Aspectj&#x5B9E;&#x73B0;AOP&#x64CD;&#x4F5C;</strong></p>
<p>1.&#x57FA;&#x4E8E;xml&#x914D;&#x7F6E;&#x6587;&#x4EF6;</p>
<p>2.&#x57FA;&#x4E8E;&#x6CE8;&#x89E3;&#x7684;&#x5F62;&#x5F0F;&#x5B9E;&#x73B0;</p>
<p><strong>&#x5207;&#x5165;&#x70B9;&#x8868;&#x8FBE;&#x5F0F;</strong></p>
<p>&#x4F5C;&#x7528;&#xFF1A;&#x58F0;&#x660E;&#x5BF9;&#x54EA;&#x4E2A;&#x7C7B;&#x4E2D;&#x7684;&#x54EA;&#x4E2A;&#x65B9;&#x6CD5;&#x8FDB;&#x884C;&#x589E;&#x5F3A;</p>
<p>&#x8BED;&#x6CD5;&#xFF1A;</p>
<p>execution&#xFF08;[&#x8BBF;&#x95EE;&#x6743;&#x9650;&#x4FEE;&#x9970;&#x7B26;]  &#x8FD4;&#x56DE;&#x503C;  [ &#x7C7B;&#x7684;&#x5168;&#x8DEF;&#x5F84;&#x540D; ]  &#x65B9;&#x6CD5;&#x540D;(&#x53C2;&#x6570;&#x5217;&#x8868;) [ &#x5F02;&#x5E38; ]&#xFF09;</p>
<p>&#x65B9;&#x5F0F;1&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AfterLog</span>  <span class="hljs-keyword">implements</span> <span class="hljs-title">AfterReturningAdvice</span> </span>{
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">afterReturning</span><span class="hljs-params">(Object o, Method method, Object[] objects, Object o1)</span> <span class="hljs-keyword">throws</span> Throwable </span>{
        System.out.println(method.getName()+<span class="hljs-string">&quot;&#x65B9;&#x6CD5;&#x88AB;&#x6267;&#x884C;&#xFF0C;&#x8FD4;&#x56DE;&#x503C;&#x662F;&#xFF1A;&quot;</span>+o);
    }
}

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Log</span>  <span class="hljs-keyword">implements</span> <span class="hljs-title">MethodBeforeAdvice</span> </span>{
    <span class="hljs-comment">/**
     *
     * <span class="hljs-doctag">@param</span> method &#x76EE;&#x6807;&#x5BF9;&#x8C61;&#x7684;&#x65B9;&#x6CD5;
     * <span class="hljs-doctag">@param</span> objects  &#x53C2;&#x6570;
     * <span class="hljs-doctag">@param</span> o  &#x76EE;&#x6807;&#x5BF9;&#x8C61;
     * <span class="hljs-doctag">@throws</span> Throwable
     */</span>
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">before</span><span class="hljs-params">(Method method, Object[] objects, Object o)</span> <span class="hljs-keyword">throws</span> Throwable </span>{
        System.out.println(o.getClass().getName()+<span class="hljs-string">&quot;&#x7684;&quot;</span>+method.getName()+<span class="hljs-string">&quot;&#x65B9;&#x6CD5;&#x88AB;&#x6267;&#x884C;&quot;</span>);
    }
}
</code></pre>
<pre><code class="lang-java">&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
       xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot;
       xsi:schemaLocation=
               &quot;http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/aop
               http://www.springframework.org/schema/aop/spring-aop.xsd&quot;&gt;
    &lt;bean id=&quot;log&quot; class=&quot;cn.kgc.spring.service.Log&quot;&gt;&lt;/bean&gt;
    &lt;bean id=&quot;afterlog&quot; class=&quot;cn.kgc.spring.service.AfterLog&quot;/&gt;
    &lt;bean id=&quot;studentServiceImpl&quot; class=&quot;cn.kgc.spring.service.StudentServiceImpl&quot;/&gt;
&lt;!--&#x914D;&#x7F6E;aop--&gt;
&lt;aop:config&gt;
&lt;!--    &#x5207;&#x5165;&#x70B9;execution() &#x8981;&#x6267;&#x884C;&#x7684;&#x4F4D;&#x7F6E;--&gt;

    &lt;aop:pointcut id=&quot;pointcut&quot; expression=&quot;execution(* cn.kgc.spring.service.StudentServiceImpl.*(..))&quot;/&gt;
&lt;!--    &#x6267;&#x884C;&#x73AF;&#x7ED5;&#x589E;&#x5F3A;--&gt;
    &lt;aop:advisor advice-ref=&quot;log&quot; pointcut-ref=&quot;pointcut&quot;/&gt;
    &lt;aop:advisor advice-ref=&quot;afterlog&quot; pointcut-ref=&quot;pointcut&quot;/&gt;
&lt;/aop:config&gt;
&lt;/beans&gt;
</code></pre>
<p>&#x65B9;&#x5F0F;2&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PointCut</span> </span>{

     <span class="hljs-comment">//&#x524D;&#x7F6E;&#x901A;&#x77E5;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">beforeMethod</span><span class="hljs-params">()</span></span>{
        System.out.println(<span class="hljs-string">&quot;&#x5F00;&#x542F;&#x4E8B;&#x52A1;&quot;</span>);
    }
    <span class="hljs-comment">//&#x540E;&#x7F6E;&#x901A;&#x77E5;  &#x5207;&#x70B9;&#x65B9;&#x6CD5;&#x6B63;&#x5E38;&#x6267;&#x884C;&#x4E4B;&#x540E;&#x6267;&#x884C;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">afterMethod</span><span class="hljs-params">()</span></span>{
        System.out.println(<span class="hljs-string">&quot;&#x5173;&#x95ED;&#x4E8B;&#x52A1;&quot;</span>);
    }

    <span class="hljs-comment">//&#x73AF;&#x7ED5;&#x901A;&#x77E5;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">around</span><span class="hljs-params">(ProceedingJoinPoint jp)</span>  </span>{


        <span class="hljs-keyword">try</span> {
            System.out.println(<span class="hljs-string">&quot;------&#x73AF;&#x7ED5;&#x524D;------&quot;</span>);
            Object proceed = jp.proceed();
            System.out.println(<span class="hljs-string">&quot;------&#x73AF;&#x7ED5;&#x540E;------&quot;</span>);
        } <span class="hljs-keyword">catch</span> (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println(<span class="hljs-string">&quot;&#x5F02;&#x5E38;&#x901A;&#x77E5;&quot;</span>);
        }<span class="hljs-keyword">finally</span> {
            System.out.println(<span class="hljs-string">&quot;&#x6700;&#x7EC8;&#x901A;&#x77E5;&quot;</span>);
        }

    }

    <span class="hljs-comment">//&#x6700;&#x7EC8;&#x901A;&#x77E5;  &#x65E0;&#x8BBA;&#x5207;&#x70B9;&#x65B9;&#x6CD5;&#x662F;&#x5426;&#x6B63;&#x5E38;&#x6267;&#x884C; &#x90FD;&#x4F1A;&#x5728;&#x5176;&#x540E;&#x6267;&#x884C;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">fy</span><span class="hljs-params">()</span></span>{
        System.out.println(<span class="hljs-string">&quot;&#x6700;&#x7EC8;&#x901A;&#x77E5;&quot;</span>);
    }

    <span class="hljs-comment">//&#x5F02;&#x5E38;&#x901A;&#x77E5;   &#x548C;&#x540E;&#x7F6E;&#x901A;&#x77E5;&#x6C38;&#x8FDC;&#x53EA;&#x80FD;&#x6267;&#x884C;&#x4E00;&#x4E2A;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">exceptionMethod</span><span class="hljs-params">()</span></span>{
        System.out.println(<span class="hljs-string">&quot;&#x5F02;&#x5E38;&#x901A;&#x77E5;&quot;</span>);
    }

}
</code></pre>
<pre><code class="lang-xml">  <span class="hljs-tag">&lt;<span class="hljs-name">aop:config</span>&gt;</span>
<span class="hljs-comment">&lt;!--        &#x81EA;&#x5B9A;&#x4E49;&#x5207;&#x9762;--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">aop:aspect</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;point&quot;</span>&gt;</span>
<span class="hljs-comment">&lt;!--            &#x5207;&#x5165;&#x70B9;--&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">aop:pointcut</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;pt&quot;</span> <span class="hljs-attr">expression</span>=<span class="hljs-string">&quot;execution(* cn.kgc.spring.service.StudentServiceImpl.*(..))&quot;</span>/&gt;</span>
<span class="hljs-comment">&lt;!--            &#x901A;&#x77E5;--&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">aop:before</span> <span class="hljs-attr">method</span>=<span class="hljs-string">&quot;before&quot;</span> <span class="hljs-attr">pointcut-ref</span>=<span class="hljs-string">&quot;pt&quot;</span>/&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">aop:after</span> <span class="hljs-attr">method</span>=<span class="hljs-string">&quot;after&quot;</span> <span class="hljs-attr">pointcut-ref</span>=<span class="hljs-string">&quot;pt&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">aop:aspect</span>&gt;</span>

    <span class="hljs-tag">&lt;/<span class="hljs-name">aop:config</span>&gt;</span>
</code></pre>
<p>&#x65B9;&#x5F0F;3&#xFF1A;&#x6CE8;&#x89E3;&#x65B9;&#x5F0F;</p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span><span class="hljs-meta">?&gt;</span></span>
<span class="hljs-tag">&lt;<span class="hljs-name">beans</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/beans&quot;</span>
       <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
       <span class="hljs-attr">xmlns:aop</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/aop&quot;</span>
       <span class="hljs-attr">xmlns:context</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/context&quot;</span>
       <span class="hljs-attr">xsi:schemaLocation</span>=
               &quot;<span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">beans</span>
               <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">beans</span>/<span class="hljs-attr">spring-beans.xsd</span>
                <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">aop</span>
               <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">aop</span>/<span class="hljs-attr">spring-aop.xsd</span>
                <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">context</span>
               <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">context</span>/<span class="hljs-attr">spring-context.xsd</span>&quot;&gt;</span>
    <span class="hljs-comment">&lt;!--&#x5F00;&#x542F;&#x6CE8;&#x89E3;&#x626B;&#x63CF;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">context:component-scan</span> <span class="hljs-attr">base-package</span>=<span class="hljs-string">&quot;cn.kgc.spring&quot;</span>/&gt;</span>
    <span class="hljs-comment">&lt;!--&#x5F00;&#x542F;aop&#x6CE8;&#x89E3;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">aop:aspectj-autoproxy</span>/&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">beans</span>&gt;</span>
</code></pre>
<pre><code class="lang-java"><span class="hljs-meta">@Component</span>
<span class="hljs-meta">@Aspect</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">PointCut2</span> </span>{

    <span class="hljs-comment">//&#x524D;&#x7F6E;&#x901A;&#x77E5;</span>
    <span class="hljs-meta">@Before</span>(<span class="hljs-string">&quot;execution(* cn.kgc.spring.service.StudentServiceImpl.*(..))&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">beforeMethod</span><span class="hljs-params">()</span></span>{
        System.out.println(<span class="hljs-string">&quot;&#x5F00;&#x542F;&#x4E8B;&#x52A1;&quot;</span>);
    }
    <span class="hljs-comment">//&#x540E;&#x7F6E;&#x901A;&#x77E5;  &#x5207;&#x70B9;&#x65B9;&#x6CD5;&#x6B63;&#x5E38;&#x6267;&#x884C;&#x4E4B;&#x540E;&#x6267;&#x884C;</span>
    <span class="hljs-meta">@AfterReturning</span>(<span class="hljs-string">&quot;execution(* cn.kgc.spring.service.StudentServiceImpl.*(..))&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">afterMethod</span><span class="hljs-params">()</span></span>{
        System.out.println(<span class="hljs-string">&quot;&#x5173;&#x95ED;&#x4E8B;&#x52A1;&quot;</span>);
    }

    <span class="hljs-comment">//&#x73AF;&#x7ED5;&#x901A;&#x77E5;</span>
    <span class="hljs-meta">@Around</span>(<span class="hljs-string">&quot;execution(* cn.kgc.spring.service.StudentServiceImpl.*(..))&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">around</span><span class="hljs-params">(ProceedingJoinPoint jp)</span></span>{

        <span class="hljs-keyword">try</span> {
            System.out.println(<span class="hljs-string">&quot;------&#x73AF;&#x7ED5;&#x524D;------&quot;</span>);
            Object proceed = jp.proceed();
            System.out.println(<span class="hljs-string">&quot;------&#x73AF;&#x7ED5;&#x540E;------&quot;</span>);
        } <span class="hljs-keyword">catch</span> (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println(<span class="hljs-string">&quot;&#x5F02;&#x5E38;&#x901A;&#x77E5;&quot;</span>);
        }<span class="hljs-keyword">finally</span> {
            System.out.println(<span class="hljs-string">&quot;&#x6700;&#x7EC8;&#x901A;&#x77E5;&quot;</span>);
        }

    }

    <span class="hljs-comment">//&#x6700;&#x7EC8;&#x901A;&#x77E5;  &#x65E0;&#x8BBA;&#x5207;&#x70B9;&#x65B9;&#x6CD5;&#x662F;&#x5426;&#x6B63;&#x5E38;&#x6267;&#x884C; &#x90FD;&#x4F1A;&#x5728;&#x5176;&#x540E;&#x6267;&#x884C;</span>
    <span class="hljs-meta">@After</span>(<span class="hljs-string">&quot;execution(* cn.kgc.spring.service.StudentServiceImpl.*(..))&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">fy</span><span class="hljs-params">()</span></span>{
        System.out.println(<span class="hljs-string">&quot;&#x6700;&#x7EC8;&#x901A;&#x77E5;&quot;</span>);
    }

    <span class="hljs-comment">//&#x5F02;&#x5E38;&#x901A;&#x77E5;   &#x548C;&#x540E;&#x7F6E;&#x901A;&#x77E5;&#x6C38;&#x8FDC;&#x53EA;&#x80FD;&#x6267;&#x884C;&#x4E00;&#x4E2A;</span>
    <span class="hljs-meta">@AfterThrowing</span>(<span class="hljs-string">&quot;execution(* cn.kgc.spring.service.StudentServiceImpl.*(..))&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">exceptionMethod</span><span class="hljs-params">()</span></span>{
        System.out.println(<span class="hljs-string">&quot;&#x5F02;&#x5E38;&#x901A;&#x77E5;&quot;</span>);
    }

}
</code></pre>
<h2 id="sm&#x6846;&#x67B6;&#x7684;&#x6574;&#x5408;">SM&#x6846;&#x67B6;&#x7684;&#x6574;&#x5408;</h2>
<p><strong>1.&#x5F15;&#x5165;&#x4F9D;&#x8D56;</strong></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependencies</span>&gt;</span>
<span class="hljs-comment">&lt;!--    mysql&#x9A71;&#x52A8;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>mysql<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mysql-connector-java<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.1.44<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-comment">&lt;!--druid--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.alibaba<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>druid<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.1.10<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-comment">&lt;!--mybatis--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.mybatis<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mybatis<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>3.5.7<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-comment">&lt;!--IOC &#x4F9D;&#x8D56;&#x6CE8;&#x5165;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-context<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.3.9<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-comment">&lt;!--mybatis&amp;spring &#x6574;&#x5408;&#x5305;--&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.mybatis<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mybatis-spring<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.0.5<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-comment">&lt;!--aspects &#x5207;&#x9762;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-aspects<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.3.9<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-comment">&lt;!--jdbc--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-jdbc<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.3.9<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-comment">&lt;!--lombok--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.projectlombok<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>lombok<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.18.16<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-comment">&lt;!-- &#x65E5;&#x5FD7;&#x5DE5;&#x5177;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>log4j<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>log4j<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.2.17<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-comment">&lt;!--mybatis&#x5206;&#x9875;&#x63D2;&#x4EF6;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.github.pagehelper<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>pagehelper<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.2.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
<span class="hljs-comment">&lt;!--&#x6D4B;&#x8BD5;&#x5DE5;&#x5177;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>junit<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>junit<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>4.11<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>test<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

  <span class="hljs-tag">&lt;/<span class="hljs-name">dependencies</span>&gt;</span>

-----------------------------------------------------------------------------------
<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>junit<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>junit<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>4.12<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-beans<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.3.7<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-core<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.3.7<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-context<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.3.7<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-expression<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.3.7<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>commons-logging<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>commons-logging<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.2<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.mybatis<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mybatis<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>3.5.7<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.mybatis<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mybatis-spring<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>2.0.5<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-jdbc<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.3.7<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>mysql<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>mysql-connector-java<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.1.47<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.github.pagehelper<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>pagehelper<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.2.1<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>


    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>log4j<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>log4j<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.2.17<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.alibaba<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>druid<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.1.12<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>


    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-test<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>5.3.7<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.projectlombok<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>lombok<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.18.22<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<p><strong>2.&#x914D;&#x7F6E;spring&#x7684;&#x6587;&#x4EF6;</strong></p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span><span class="hljs-meta">?&gt;</span></span>
<span class="hljs-tag">&lt;<span class="hljs-name">beans</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/beans&quot;</span>
       <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
       <span class="hljs-attr">xmlns:aop</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/aop&quot;</span>
       <span class="hljs-attr">xmlns:context</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/context&quot;</span>
       <span class="hljs-attr">xsi:schemaLocation</span>=
               &quot;<span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">beans</span>
               <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">beans</span>/<span class="hljs-attr">spring-beans.xsd</span>
                <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">aop</span>
               <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">aop</span>/<span class="hljs-attr">spring-aop.xsd</span>
                <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">context</span>
               <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">context</span>/<span class="hljs-attr">spring-context.xsd</span>&quot;&gt;</span>
    <span class="hljs-comment">&lt;!--&#x5F15;&#x5165;&#x5916;&#x90E8;&#x7684;&#x6570;&#x636E;&#x6E90;&#x914D;&#x7F6E;&#x6587;&#x4EF6;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">context:property-placeholder</span> <span class="hljs-attr">location</span>=<span class="hljs-string">&quot;db.properties&quot;</span>/&gt;</span>
    <span class="hljs-comment">&lt;!--&#x914D;&#x7F6E;druid&#x6570;&#x636E;&#x5E93;&#x8FDE;&#x63A5;&#x6C60;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;druid&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;com.alibaba.druid.pool.DruidDataSource&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;driverClassName&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.driver}&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;url&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.url}&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;username&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.username}&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;password&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;${jdbc.password}&quot;</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>

    <span class="hljs-comment">&lt;!--sqlSessionFactory--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;ssf&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;org.mybatis.spring.SqlSessionFactoryBean&quot;</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x914D;&#x7F6E;&#x6570;&#x636E;&#x6E90;--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;dataSource&quot;</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;druid&quot;</span>/&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x6CE8;&#x5165;mybatis&#x7684;&#x6838;&#x5FC3;&#x914D;&#x7F6E;&#x6587;&#x4EF6;--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;configLocation&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;classpath:mybatis-config.xml&quot;</span>/&gt;</span>
    <span class="hljs-comment">&lt;!--mapper&#x6620;&#x5C04;&#x6587;&#x4EF6;--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;mapperLocations&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;classpath:mapper/*.xml&quot;</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>

    <span class="hljs-comment">&lt;!--&#x626B;&#x63CF;&#x6240;&#x6709;&#x7684;&#x63A5;&#x53E3;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;org.mybatis.spring.mapper.MapperScannerConfigurer&quot;</span>&gt;</span>
        <span class="hljs-comment">&lt;!--&#x626B;&#x63CF;&#x6240;&#x6709;&#x7684;&#x63A5;&#x53E3;&#xFF0C;&#x751F;&#x6210;&#x4EE3;&#x7406;&#x5BF9;&#x8C61;&#xFF0C;&#x6CE8;&#x5165;spring&#x5BB9;&#x5668;--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;basePackage&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;cn.kgc.spring.dao&quot;</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">beans</span>&gt;</span>
</code></pre>
<p>3.&#x914D;&#x7F6E;mybatis&#x6587;&#x4EF6;</p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span> <span class="hljs-meta">?&gt;</span></span>
<span class="hljs-meta">&lt;!DOCTYPE configuration
        PUBLIC &quot;-//mybatis.org//DTD Config 3.0//EN&quot;
        &quot;http://mybatis.org/dtd/mybatis-3-config.dtd&quot;&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">settings</span>&gt;</span>
    <span class="hljs-comment">&lt;!--&#x5F00;&#x542F;&#x5B57;&#x6BB5;&#x7684;&#x9A7C;&#x5CF0;&#x547D;&#x540D;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">setting</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;mapUnderscoreToCamelCase&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;true&quot;</span>/&gt;</span>
    <span class="hljs-comment">&lt;!--&#x5F00;&#x542F;&#x65E5;&#x5FD7;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">setting</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;logImpl&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;LOG4J&quot;</span>/&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">settings</span>&gt;</span>
    <span class="hljs-comment">&lt;!--&#x8BBE;&#x7F6E;&#x5B9E;&#x4F53;&#x7C7B;&#x7684;&#x522B;&#x540D;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">typeAliases</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">package</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;cn.kgc.mybatis.entity&quot;</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">typeAliases</span>&gt;</span>
   <span class="hljs-comment">&lt;!-- &#x5206;&#x9875;&#x914D;&#x7F6E;--&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">plugins</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">plugin</span> <span class="hljs-attr">interceptor</span>=<span class="hljs-string">&quot;com.github.pagehelper.PageInterceptor&quot;</span>&gt;</span>
            <span class="hljs-comment">&lt;!-- &#x914D;&#x7F6E;mysql&#x65B9;&#x8A00; --&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;helperDialect&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;mysql&quot;</span> /&gt;</span>
            <span class="hljs-comment">&lt;!-- &#x8BBE;&#x7F6E;&#x4E3A;true&#x65F6;&#xFF0C;&#x5982;&#x679C;pageSize=0&#x5C31;&#x4F1A;&#x67E5;&#x8BE2;&#x51FA;&#x5168;&#x90E8;&#x7684;&#x7ED3;&#x679C; --&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;pageSizeZero&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;true&quot;</span> /&gt;</span>
            <span class="hljs-comment">&lt;!-- 3.3.0&#x7248;&#x672C;&#x53EF;&#x7528;&#xFF0C;&#x5206;&#x9875;&#x53C2;&#x6570;&#x5408;&#x7406;&#x5316;&#xFF0C;&#x9ED8;&#x8BA4;false&#x7981;&#x7528; --&gt;</span>
            <span class="hljs-comment">&lt;!-- &#x542F;&#x7528;&#x5408;&#x7406;&#x5316;&#x65F6;&#xFF0C;&#x5982;&#x679C;pageNum&lt;1&#x4F1A;&#x67E5;&#x8BE2;&#x7B2C;&#x4E00;&#x9875;&#xFF0C;&#x5982;&#x679C;pageNum&gt;pages&#x4F1A;&#x67E5;&#x8BE2;&#x6700;&#x540E;&#x4E00;&#x9875; --&gt;</span>
            <span class="hljs-comment">&lt;!-- &#x7981;&#x7528;&#x5408;&#x7406;&#x5316;&#x65F6;&#xFF0C;&#x5982;&#x679C;pageNum&lt;1&#x6216;pageNum&gt;pages&#x4F1A;&#x8FD4;&#x56DE;&#x7A7A;&#x6570;&#x636E; --&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;reasonable&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;true&quot;</span> /&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">plugin</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">plugins</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x65E5;&#x5FD7;&#x6587;&#x4EF6; (log4j.properties)</p>
<pre><code class="lang-properties">log4j.rootLogger=DEBUG,Console

#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Target=System.out
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n

log4j.logger.org.apache=ERROR
log4j.logger.org.mybatis=ERROR
log4j.logger.org.springframework=ERROR

#&#x8FD9;&#x4E2A;&#x9700;&#x8981;
log4j.logger.log4jdbc.debug=ERROR
log4j.logger.com.gk.mapper=ERROR
log4j.logger.jdbc.audit=ERROR
log4j.logger.jdbc.resultset=ERROR
#&#x8FD9;&#x4E2A;&#x6253;&#x5370;SQL&#x8BED;&#x53E5;&#x975E;&#x5E38;&#x91CD;&#x8981;
log4j.logger.jdbc.sqlonly=DEBUG
log4j.logger.jdbc.sqltiming=ERROR
log4j.logger.jdbc.connection=FATAL
</code></pre>
<p>4.&#x7F16;&#x5199;&#x6D4B;&#x8BD5;&#x7C7B; &#x6D4B;&#x8BD5;</p>
<pre><code class="lang-java"><span class="hljs-comment">/**
 *
 * junit&#x7248;&#x672C;&#x8981;&#x6C42;4.12&#x4EE5;&#x4E0A;
 * <span class="hljs-doctag">@author</span> mosin
 * date 2021/11/15
 * <span class="hljs-doctag">@version</span> 1.0
 */</span>
<span class="hljs-meta">@RunWith</span>(SpringJUnit4ClassRunner.class)
<span class="hljs-meta">@ContextConfiguration</span>(<span class="hljs-string">&quot;classpath:config/applicationcontext.xml&quot;</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">TestStudent</span> </span>{
    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> StudentService studentService;

    <span class="hljs-meta">@Test</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">test01</span><span class="hljs-params">()</span></span>{

        <span class="hljs-comment">//  Integer integer = studentService.delOne(500062);</span>
        <span class="hljs-comment">//  System.out.println(integer);</span>
        <span class="hljs-comment">// Student student = studentService.selectOne(500062);</span>
        <span class="hljs-comment">// System.out.println(student);</span>
        <span class="hljs-comment">//</span>
        <span class="hljs-comment">// Integer integer1 = studentService.addOne(Student.builder().stuName(&quot;lisi&quot;).stuBirth(new Date()).stuSex(&quot;&#x7537;&quot;).stuNo(&quot;2021111501&quot;).build());</span>
        <span class="hljs-comment">// System.out.println(integer1);</span>

        <span class="hljs-comment">// Student student2 = studentService.selectOne(500073);</span>
        <span class="hljs-comment">// System.out.println(student2);</span>
        <span class="hljs-comment">// PageHelper.startPage(1, 20);</span>
        <span class="hljs-comment">// List&lt;Student&gt; students = studentService.selectAll();</span>
        <span class="hljs-comment">// PageInfo&lt;Student&gt; studentPageInfo = new PageInfo&lt;&gt;(students);</span>
        <span class="hljs-comment">//</span>
        <span class="hljs-comment">// System.out.println(studentPageInfo.getList());</span>


        studentService.updateStudent(Student.builder().stuName(<span class="hljs-string">&quot;&#x674E;&#x56DB;&quot;</span>).stuBirth(<span class="hljs-keyword">new</span> Date()).stuSex(<span class="hljs-string">&quot;&#x7537;&quot;</span>).stuNo(<span class="hljs-string">&quot;2021111501&quot;</span>).id(<span class="hljs-number">500073</span>).build());

    }

}
</code></pre>
<h2 id="spring&#x4E2D;&#x7684;&#x4E8B;&#x52A1;">spring&#x4E2D;&#x7684;&#x4E8B;&#x52A1;</h2>
<p>1.&#x914D;&#x7F6E;&#x5F0F;&#x4E8B;&#x52A1;</p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span><span class="hljs-meta">?&gt;</span></span>
<span class="hljs-tag">&lt;<span class="hljs-name">beans</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/beans&quot;</span>
       <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
       <span class="hljs-attr">xmlns:aop</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/aop&quot;</span>
       <span class="hljs-attr">xmlns:context</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/context&quot;</span>
       <span class="hljs-attr">xmlns:tx</span>=<span class="hljs-string">&quot;http://www.springframework.org/schema/tx&quot;</span>
       <span class="hljs-attr">xsi:schemaLocation</span>=
                 &quot;<span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">beans</span>
                 <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">beans</span>/<span class="hljs-attr">spring-beans.xsd</span>
                 <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">aop</span>
                 <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">aop</span>/<span class="hljs-attr">spring-aop.xsd</span>
                 <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">context</span>
                 <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">context</span>/<span class="hljs-attr">spring-context.xsd</span>
                 <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">tx</span>
                 <span class="hljs-attr">http:</span>//<span class="hljs-attr">www.springframework.org</span>/<span class="hljs-attr">schema</span>/<span class="hljs-attr">tx</span>/<span class="hljs-attr">spring-tx.xsd</span>&quot;&gt;</span>

<span class="hljs-comment">&lt;!--    &#x6CE8;&#x5165;&#x4E8B;&#x52A1;&#x7BA1;&#x7406;&#x5668;--&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;dataSourceTransactionManager&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;org.springframework.jdbc.datasource.DataSourceTransactionManager&quot;</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;dataSource&quot;</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;druid&quot;</span>/&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">bean</span>&gt;</span>

<span class="hljs-comment">&lt;!--&#x914D;&#x7F6E;&#x4E8B;&#x52A1;&#x901A;&#x77E5;--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">tx:advice</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;tx&quot;</span> <span class="hljs-attr">transaction-manager</span>=<span class="hljs-string">&quot;dataSourceTransactionManager&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tx:attributes</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">tx:method</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;save&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">tx:method</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;delete&quot;</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">tx:attributes</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">tx:advice</span>&gt;</span>

<span class="hljs-comment">&lt;!--&#x914D;&#x7F6E;&#x4E8B;&#x52A1;&#x7684;aop--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">aop:config</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">aop:pointcut</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;servicePoint&quot;</span> <span class="hljs-attr">expression</span>=<span class="hljs-string">&quot;execution(* cn.kgc.spring.service.*.*(..))&quot;</span>/&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">aop:advisor</span> <span class="hljs-attr">advice-ref</span>=<span class="hljs-string">&quot;tx&quot;</span> <span class="hljs-attr">pointcut-ref</span>=<span class="hljs-string">&quot;servicePoint&quot;</span>/&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">aop:config</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">beans</span>&gt;</span>
</code></pre>
<p>2.&#x58F0;&#x660E;&#x5F0F;&#x4E8B;&#x52A1;</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!--    &#x5F00;&#x542F;&#x4E8B;&#x52A1;&#x6CE8;&#x89E3;&#x652F;&#x6301;--&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">tx:annotation-driven</span> <span class="hljs-attr">transaction-manager</span>=<span class="hljs-string">&quot;dataSourceTransactionManager&quot;</span>/&gt;</span>
</code></pre>
<pre><code class="lang-java"><span class="hljs-meta">@Service</span>(<span class="hljs-string">&quot;studentService&quot;</span>)
<span class="hljs-meta">@Transactional</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">StudentServiceImpl</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">StudentService</span> </span>{
    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> StudentDao studentDao;
    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> List&lt;Student&gt; <span class="hljs-title">getAll</span><span class="hljs-params">()</span> </span>{
        List&lt;Student&gt; all = studentDao.getAll();
        <span class="hljs-keyword">return</span> all;
    }

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">save</span><span class="hljs-params">(Student student)</span></span>{
        <span class="hljs-keyword">int</span> line = studentDao.save(student);
        <span class="hljs-keyword">int</span> a = <span class="hljs-number">1</span>/<span class="hljs-number">0</span>;
        <span class="hljs-keyword">return</span> line;
    }
}
</code></pre>
<p><strong>&#x4E8B;&#x52A1;&#x4F20;&#x64AD;&#x65B9;&#x5F0F;</strong></p>
<p>&#x4E8B;&#x52A1;&#x6700;&#x91CD;&#x8981;&#x7684;&#x4E24;&#x4E2A;&#x7279;&#x6027;&#xFF0C;&#x662F;&#x4E8B;&#x52A1;&#x7684;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x548C;&#x6570;&#x636E;&#x9694;&#x79BB;&#x7EA7;&#x522B;&#x3002;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x5B9A;&#x4E49;&#x7684;&#x662F;&#x4E8B;&#x52A1;&#x7684;&#x63A7;&#x5236;&#x8303;&#x56F4;&#xFF0C;&#x4E8B;&#x52A1;&#x9694;&#x79BB;&#x7EA7;&#x522B;&#x5B9A;&#x4E49;&#x7684;&#x662F;&#x4E8B;&#x52A1;&#x5728;&#x6570;&#x636E;&#x5E93;&#x8BFB;&#x5199;&#x65B9;&#x9762;&#x7684;&#x63A7;&#x5236;&#x8303;&#x56F4;&#x3002;</p>
<p>&#x4EE5;&#x4E0B;&#x662F;&#x4E8B;&#x52A1;&#x7684;7&#x79CD;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#xFF1A;</p>
<p>1&#xFF09; <strong><em>\</em>PROPAGATION_REQUIRED**</strong> &#xFF0C;&#x9ED8;&#x8BA4;&#x7684;spring&#x4E8B;&#x52A1;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#xFF0C;&#x4F7F;&#x7528;&#x8BE5;&#x7EA7;&#x522B;&#x7684;&#x7279;&#x70B9;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x5DF2;&#x7ECF;&#x5B58;&#x5728;&#x4E8B;&#x52A1;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x52A0;&#x5165;&#x5230;&#x4E8B;&#x52A1;&#x4E2D;&#x6267;&#x884C;&#xFF0C;&#x5982;&#x679C;&#x5F53;&#x524D;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x4E0D;&#x5B58;&#x5728;&#x4E8B;&#x52A1;&#xFF0C;&#x5219;&#x65B0;&#x5EFA;&#x4E8B;&#x52A1;&#x6267;&#x884C;&#x3002;&#x6240;&#x4EE5;&#x8FD9;&#x4E2A;&#x7EA7;&#x522B;&#x901A;&#x5E38;&#x80FD;&#x6EE1;&#x8DB3;&#x5904;&#x7406;&#x5927;&#x591A;&#x6570;&#x7684;&#x4E1A;&#x52A1;&#x573A;&#x666F;&#x3002;</p>
<p>2&#xFF09;<strong><em>\</em>PROPAGATION_SUPPORTS**</strong> &#xFF0C;&#x4ECE;&#x5B57;&#x9762;&#x610F;&#x601D;&#x5C31;&#x77E5;&#x9053;&#xFF0C;supports&#xFF0C;&#x652F;&#x6301;&#xFF0C;&#x8BE5;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x7684;&#x7279;&#x70B9;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x4E0A;&#x4E0B;&#x6587;&#x5B58;&#x5728;&#x4E8B;&#x52A1;&#xFF0C;&#x5219;&#x652F;&#x6301;&#x4E8B;&#x52A1;&#x52A0;&#x5165;&#x4E8B;&#x52A1;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x4E8B;&#x52A1;&#xFF0C;&#x5219;&#x4F7F;&#x7528;&#x975E;&#x4E8B;&#x52A1;&#x7684;&#x65B9;&#x5F0F;&#x6267;&#x884C;&#x3002;&#x6240;&#x4EE5;&#x8BF4;&#xFF0C;&#x5E76;&#x975E;&#x6240;&#x6709;&#x7684;&#x5305;&#x5728;transactionTemplate.execute&#x4E2D;&#x7684;&#x4EE3;&#x7801;&#x90FD;&#x4F1A;&#x6709;&#x4E8B;&#x52A1;&#x652F;&#x6301;&#x3002;&#x8FD9;&#x4E2A;&#x901A;&#x5E38;&#x662F;&#x7528;&#x6765;&#x5904;&#x7406;&#x90A3;&#x4E9B;&#x5E76;&#x975E;&#x539F;&#x5B50;&#x6027;&#x7684;&#x975E;&#x6838;&#x5FC3;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x64CD;&#x4F5C;&#x3002;&#x5E94;&#x7528;&#x573A;&#x666F;&#x8F83;&#x5C11;&#x3002;</p>
<p>3&#xFF09;<strong><em>\</em>PROPAGATION_MANDATORY**</strong> &#xFF0C; &#x8BE5;&#x7EA7;&#x522B;&#x7684;&#x4E8B;&#x52A1;&#x8981;&#x6C42;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x5FC5;&#x987B;&#x8981;&#x5B58;&#x5728;&#x4E8B;&#x52A1;&#xFF0C;&#x5426;&#x5219;&#x5C31;&#x4F1A;&#x629B;&#x51FA;&#x5F02;&#x5E38;&#xFF01;&#x914D;&#x7F6E;&#x8BE5;&#x65B9;&#x5F0F;&#x7684;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x662F;&#x6709;&#x6548;&#x7684;&#x63A7;&#x5236;&#x4E0A;&#x4E0B;&#x6587;&#x8C03;&#x7528;&#x4EE3;&#x7801;&#x9057;&#x6F0F;&#x6DFB;&#x52A0;&#x4E8B;&#x52A1;&#x63A7;&#x5236;&#x7684;&#x4FDD;&#x8BC1;&#x624B;&#x6BB5;&#x3002;&#x6BD4;&#x5982;&#x4E00;&#x6BB5;&#x4EE3;&#x7801;&#x4E0D;&#x80FD;&#x5355;&#x72EC;&#x88AB;&#x8C03;&#x7528;&#x6267;&#x884C;&#xFF0C;&#x4F46;&#x662F;&#x4E00;&#x65E6;&#x88AB;&#x8C03;&#x7528;&#xFF0C;&#x5C31;&#x5FC5;&#x987B;&#x6709;&#x4E8B;&#x52A1;&#x5305;&#x542B;&#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x3002;</p>
<p>4&#xFF09;<strong><em>\</em>PROPAGATION_REQUIRES_NEW**</strong> &#xFF0C;&#x4ECE;&#x5B57;&#x9762;&#x5373;&#x53EF;&#x77E5;&#x9053;&#xFF0C;new&#xFF0C;&#x6BCF;&#x6B21;&#x90FD;&#x8981;&#x4E00;&#x4E2A;&#x65B0;&#x4E8B;&#x52A1;&#xFF0C;&#x8BE5;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x7684;&#x7279;&#x70B9;&#x662F;&#xFF0C;&#x6BCF;&#x6B21;&#x90FD;&#x4F1A;&#x65B0;&#x5EFA;&#x4E00;&#x4E2A;&#x4E8B;&#x52A1;&#xFF0C;&#x5E76;&#x4E14;&#x540C;&#x65F6;&#x5C06;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x7684;&#x4E8B;&#x52A1;&#x6302;&#x8D77;&#xFF0C;&#x6267;&#x884C;&#x5F53;&#x524D;&#x65B0;&#x5EFA;&#x4E8B;&#x52A1;&#x5B8C;&#x6210;&#x4EE5;&#x540E;&#xFF0C;&#x4E0A;&#x4E0B;&#x6587;&#x4E8B;&#x52A1;&#x6062;&#x590D;&#x518D;&#x6267;&#x884C;&#x3002;</p>
<p>&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x5F88;&#x6709;&#x7528;&#x7684;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#xFF0C;&#x4E3E;&#x4E00;&#x4E2A;&#x5E94;&#x7528;&#x573A;&#x666F;&#xFF1A;&#x73B0;&#x5728;&#x6709;&#x4E00;&#x4E2A;&#x53D1;&#x9001;100&#x4E2A;&#x7EA2;&#x5305;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x5728;&#x53D1;&#x9001;&#x4E4B;&#x524D;&#xFF0C;&#x8981;&#x505A;&#x4E00;&#x4E9B;&#x7CFB;&#x7EDF;&#x7684;&#x521D;&#x59CB;&#x5316;&#x3001;&#x9A8C;&#x8BC1;&#x3001;&#x6570;&#x636E;&#x8BB0;&#x5F55;&#x64CD;&#x4F5C;&#xFF0C;&#x7136;&#x540E;&#x53D1;&#x9001;100&#x5C01;&#x7EA2;&#x5305;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x8BB0;&#x5F55;&#x53D1;&#x9001;&#x65E5;&#x5FD7;&#xFF0C;&#x53D1;&#x9001;&#x65E5;&#x5FD7;&#x8981;&#x6C42;100%&#x7684;&#x51C6;&#x786E;&#xFF0C;&#x5982;&#x679C;&#x65E5;&#x5FD7;&#x4E0D;&#x51C6;&#x786E;&#xFF0C;&#x90A3;&#x4E48;&#x6574;&#x4E2A;&#x7236;&#x4E8B;&#x52A1;&#x903B;&#x8F91;&#x9700;&#x8981;&#x56DE;&#x6EDA;&#x3002;
&#x600E;&#x4E48;&#x5904;&#x7406;&#x6574;&#x4E2A;&#x4E1A;&#x52A1;&#x9700;&#x6C42;&#x5462;&#xFF1F;&#x5C31;&#x662F;&#x901A;&#x8FC7;&#x8FD9;&#x4E2A;PROPAGATION_REQUIRES_NEW &#x7EA7;&#x522B;&#x7684;&#x4E8B;&#x52A1;&#x4F20;&#x64AD;&#x63A7;&#x5236;&#x5C31;&#x53EF;&#x4EE5;&#x5B8C;&#x6210;&#x3002;&#x53D1;&#x9001;&#x7EA2;&#x5305;&#x7684;&#x5B50;&#x4E8B;&#x52A1;&#x4E0D;&#x4F1A;&#x76F4;&#x63A5;&#x5F71;&#x54CD;&#x5230;&#x7236;&#x4E8B;&#x52A1;&#x7684;&#x63D0;&#x4EA4;&#x548C;&#x56DE;&#x6EDA;&#x3002;</p>
<p>5&#xFF09;<strong><em>\</em>PROPAGATION_NOT_SUPPORTED**</strong> &#xFF0C;&#x8FD9;&#x4E2A;&#x4E5F;&#x53EF;&#x4EE5;&#x4ECE;&#x5B57;&#x9762;&#x5F97;&#x77E5;&#xFF0C;not supported &#xFF0C;&#x4E0D;&#x652F;&#x6301;&#xFF0C;&#x5F53;&#x524D;&#x7EA7;&#x522B;&#x7684;&#x7279;&#x70B9;&#x5C31;&#x662F;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x5B58;&#x5728;&#x4E8B;&#x52A1;&#xFF0C;&#x5219;&#x6302;&#x8D77;&#x4E8B;&#x52A1;&#xFF0C;&#x6267;&#x884C;&#x5F53;&#x524D;&#x903B;&#x8F91;&#xFF0C;&#x7ED3;&#x675F;&#x540E;&#x6062;&#x590D;&#x4E0A;&#x4E0B;&#x6587;&#x7684;&#x4E8B;&#x52A1;&#x3002;</p>
<p>&#x8FD9;&#x4E2A;&#x7EA7;&#x522B;&#x6709;&#x4EC0;&#x4E48;&#x597D;&#x5904;&#xFF1F;&#x53EF;&#x4EE5;&#x5E2E;&#x52A9;&#x4F60;&#x5C06;&#x4E8B;&#x52A1;&#x6781;&#x53EF;&#x80FD;&#x7684;&#x7F29;&#x5C0F;&#x3002;&#x6211;&#x4EEC;&#x77E5;&#x9053;&#x4E00;&#x4E2A;&#x4E8B;&#x52A1;&#x8D8A;&#x5927;&#xFF0C;&#x5B83;&#x5B58;&#x5728;&#x7684;&#x98CE;&#x9669;&#x4E5F;&#x5C31;&#x8D8A;&#x591A;&#x3002;&#x6240;&#x4EE5;&#x5728;&#x5904;&#x7406;&#x4E8B;&#x52A1;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x8981;&#x4FDD;&#x8BC1;&#x5C3D;&#x53EF;&#x80FD;&#x7684;&#x7F29;&#x5C0F;&#x8303;&#x56F4;&#x3002;&#x6BD4;&#x5982;&#x4E00;&#x6BB5;&#x4EE3;&#x7801;&#xFF0C;&#x662F;&#x6BCF;&#x6B21;&#x903B;&#x8F91;&#x64CD;&#x4F5C;&#x90FD;&#x5FC5;&#x987B;&#x8C03;&#x7528;&#x7684;&#xFF0C;&#x6BD4;&#x5982;&#x5FAA;&#x73AF;1000&#x6B21;&#x7684;&#x67D0;&#x4E2A;&#x975E;&#x6838;&#x5FC3;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x64CD;&#x4F5C;&#x3002;&#x8FD9;&#x6837;&#x7684;&#x4EE3;&#x7801;&#x5982;&#x679C;&#x5305;&#x5728;&#x4E8B;&#x52A1;&#x4E2D;&#xFF0C;&#x52BF;&#x5FC5;&#x9020;&#x6210;&#x4E8B;&#x52A1;&#x592A;&#x5927;&#xFF0C;&#x5BFC;&#x81F4;&#x51FA;&#x73B0;&#x4E00;&#x4E9B;&#x96BE;&#x4EE5;&#x8003;&#x8651;&#x5468;&#x5168;&#x7684;&#x5F02;&#x5E38;&#x60C5;&#x51B5;&#x3002;&#x6240;&#x4EE5;&#x8FD9;&#x4E2A;&#x4E8B;&#x52A1;&#x8FD9;&#x4E2A;&#x7EA7;&#x522B;&#x7684;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x5C31;&#x6D3E;&#x4E0A;&#x7528;&#x573A;&#x4E86;&#x3002;&#x7528;&#x5F53;&#x524D;&#x7EA7;&#x522B;&#x7684;&#x4E8B;&#x52A1;&#x6A21;&#x677F;&#x62B1;&#x8D77;&#x6765;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;&#x3002;</p>
<p>6&#xFF09;<strong><em>\</em>PROPAGATION_NEVER**</strong> &#xFF0C;&#x8BE5;&#x4E8B;&#x52A1;&#x66F4;&#x4E25;&#x683C;&#xFF0C;&#x4E0A;&#x9762;&#x4E00;&#x4E2A;&#x4E8B;&#x52A1;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x53EA;&#x662F;&#x4E0D;&#x652F;&#x6301;&#x800C;&#x5DF2;&#xFF0C;&#x6709;&#x4E8B;&#x52A1;&#x5C31;&#x6302;&#x8D77;&#xFF0C;&#x800C;PROPAGATION_NEVER&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x8981;&#x6C42;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x4E0D;&#x80FD;&#x5B58;&#x5728;&#x4E8B;&#x52A1;&#xFF0C;&#x4E00;&#x65E6;&#x6709;&#x4E8B;&#x52A1;&#xFF0C;&#x5C31;&#x629B;&#x51FA;runtime&#x5F02;&#x5E38;&#xFF0C;&#x5F3A;&#x5236;&#x505C;&#x6B62;&#x6267;&#x884C;&#xFF01;&#x8FD9;&#x4E2A;&#x7EA7;&#x522B;&#x4E0A;&#x8F88;&#x5B50;&#x8DDF;&#x4E8B;&#x52A1;&#x6709;&#x4EC7;&#x3002;</p>
<p>7&#xFF09;<strong><em>\</em>PROPAGATION_NESTED**</strong> &#xFF0C;&#x5B57;&#x9762;&#x4E5F;&#x53EF;&#x77E5;&#x9053;&#xFF0C;nested&#xFF0C;&#x5D4C;&#x5957;&#x7EA7;&#x522B;&#x4E8B;&#x52A1;&#x3002;&#x8BE5;&#x4F20;&#x64AD;&#x7EA7;&#x522B;&#x7279;&#x5F81;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#x5B58;&#x5728;&#x4E8B;&#x52A1;&#xFF0C;&#x5219;&#x5D4C;&#x5957;&#x4E8B;&#x52A1;&#x6267;&#x884C;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x5B58;&#x5728;&#x4E8B;&#x52A1;&#xFF0C;&#x5219;&#x65B0;&#x5EFA;&#x4E8B;&#x52A1;&#x3002;</p>
<pre><code class="lang-java"><span class="hljs-meta">@Transactional</span>(propagation=Propagation.REQUIRED,rollbackFor=Exception.class)
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="springmvc框架.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: Springmvc框架">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Spring框架","level":"2.6.4","depth":2,"previous":{"title":"Springmvc框架","level":"2.6.3","depth":2,"path":"books/整合/springmvc框架.md","ref":"books/整合/springmvc框架.md","articles":[]},"dir":"ltr"},"config":{"plugins":["search-pro","code","back-to-top-button","theme-comscore","intopic-toc","flexible-alerts","expandable-chapters"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"intopic-toc":{"selector":".markdown-section h1, .markdown-section h2, .markdown-section h3, .markdown-section h4, .markdown-section h5, .markdown-section h6","mode":"nested","maxDepth":6,"isCollapsed":true,"isScrollspyActive":true,"visible":true,"label":"In this article"},"search-pro":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"back-to-top-button":{},"flexible-alerts":{"style":"callout","note":{"label":"Note","icon":"fa fa-info-circle","className":"info"},"tip":{"label":"Tip","icon":"fa fa-lightbulb-o","className":"tip"},"warning":{"label":"Warning","icon":"fa fa-exclamation-triangle","className":"warning"},"danger":{"label":"Attention","icon":"fa fa-ban","className":"danger"}},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"作者","lang":"zh-cn","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"isbn":"图书编号","variables":{},"title":"书名","gitbook":"*","description":"描述"},"file":{"path":"books/整合/spring框架.md","mtime":"2022-12-06T11:35:44.598Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2023-03-01T12:24:55.135Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/anchor.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/gumshoe.polyfills.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-intopic-toc/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

